pystra.distributions.zeroinflated.ZeroInflated#

class ZeroInflated(name, dist, p, input_type=None, startpoint=None)[source]#

Bases: Distribution

A Zero-Inflated rendering of the provided distribution.

Variable loads sometimes have values of zero when they are not occurring. This distribution creates a mixed distribution where there is a certain probability p of a zero value, otherwise with a probability 1-p a realization of the provided distribution occurs.

Attributes:
  • name (str): Name of the random variable

  • mean (float): Mean

  • stdv (float): Standard deviation

  • dist (Distribution): Distribution to zero-inflate

  • p (float): Probability of zero

  • input_type (any): Change meaning of mean and stdv

  • startpoint (float): Start point for seach

Methods

cdf

Cumulative distribution function

dF_dtheta

Derivatives of the CDF w.r.t.

getMean

getName

getStartPoint

getStdv

jacobian

Compute the Jacobian (e.g. Lemaire, eq.

pdf

Probability density function

plot

Plot the probability density function.

ppf

inverse cumulative distribution function

sample

Draw random samples from the distribution.

setStartPoint

set_location

Updating the zero-inflated distribution location parameter.

set_scale

Updating the zero-inflated distribution scale parameter.

set_zero_probability

Update the zero-inflated probability.

u_to_x

Transformation from u to x

x_to_u

Transformation from x to u

pdf(x)[source]#

Probability density function

cdf(x)[source]#

Cumulative distribution function

ppf(p)[source]#

inverse cumulative distribution function

u_to_x(u)[source]#

Transformation from u to x

x_to_u(x)[source]#

Transformation from x to u

jacobian(u, x)[source]#

Compute the Jacobian (e.g. Lemaire, eq. 4.9)

set_location(loc=0)[source]#

Updating the zero-inflated distribution location parameter.

set_scale(scale=1)[source]#

Updating the zero-inflated distribution scale parameter.

set_zero_probability(p)[source]#

Update the zero-inflated probability.

dF_dtheta(x)#

Derivatives of the CDF w.r.t. each sensitivity parameter.

Returns ∂F_X(x)/∂θ for every parameter listed by sensitivity_params. The base-class implementation uses central finite differences on the CDF via _make_copy().

Before computing derivatives, a reconstruction sanity check verifies that _make_copy() (with no overrides) reproduces the current distribution. This catches both constructor failures (e.g. composite distributions) and silent mismatches (e.g. distributions whose extra constructor arguments are not stored in _ctor_kwargs).

Subclasses may override this with analytical expressions for better accuracy and performance (see Normal and Lognormal).

Parameters:

x (float) – Evaluation point in physical space.

Returns:

{param_name: ∂F/∂θ} for each parameter in sensitivity_params.

Return type:

dict

Raises:

ValueError – If the distribution cannot be faithfully reconstructed by _make_copy().

plot(ax=None, **kwargs)#

Plot the probability density function.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. A new figure is created if None.

  • **kwargs – Additional keyword arguments forwarded to ax.plot().

Returns:

The axes containing the plot.

Return type:

matplotlib.axes.Axes

sample(n=1000)#

Draw random samples from the distribution.

Uses inverse-transform sampling via ppf.

Parameters:

n (int, optional) – Number of samples (default 1000).

Returns:

Array of shape (n,) with sampled values.

Return type:

ndarray

property sensitivity_params#

Distribution parameters for which sensitivities are computed.

Returns a dict {param_name: current_value} listing every parameter with respect to which \(\partial\beta/\partial\theta\) should be evaluated.

The default implementation returns {"mean": μ, "std": σ}, which is appropriate for most distributions. Distributions with additional parameters of interest (e.g. the GEV shape parameter) should override this property to include them.

Parameters listed in _ctor_kwargs but not in sensitivity_params are held fixed during sensitivity analysis — they are only used by _make_copy() to faithfully reconstruct the distribution.

Returns:

{param_name: current_value}

Return type:

dict