pystra.distributions.shiftedlognormal.ShiftedLognormal#

class ShiftedLognormal(name, mean, stdv, lower, input_type=None, startpoint=None)[source]#

Bases: Lognormal

Shifted Lognormal distribution

If X is a lognormal random variable, then Y = X + lower is a shifted lognormal random variable.

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

  • mean (float): Mean

  • stdv (float): Standard deviation

  • lower (float): Lower bound of the distribution (i.e. the shift applied to the lognormal)

  • input_type (any): Change meaning of mean and stdv. Not implemented!

  • startpoint (float): Start point for seach

Note: Could use scipy to do the heavy lifting. However, there is a small performance hit, so for this common dist use bespoke implementation for the PDF, CDF.

Methods

cdf

Cumulative distribution function

dF_dtheta

Analytical derivatives of the Lognormal CDF w.r.t.

getMean

getName

getStartPoint

getStdv

jacobian

Diagonal Jacobian of the marginal x-to-u transformation.

pdf

Probability density function Note: asssumes x>lower for performance, scipy manages this appropriately

plot

Plot the probability density function.

ppf

Percent-point function (inverse CDF).

sample

Draw random samples from the distribution.

setStartPoint

set_location

Updating the distribution location parameter.

set_lower

Updating the distribution lower parameter.

set_scale

Updating the distribution scale parameter.

u_to_x

Transformation from u to x

x_to_u

Transformation from x to u Note: asssumes x>lower for performance

pdf(x)[source]#

Probability density function Note: asssumes x>lower for performance, scipy manages this appropriately

cdf(x)[source]#

Cumulative distribution function

u_to_x(u)[source]#

Transformation from u to x

x_to_u(x)[source]#

Transformation from x to u Note: asssumes x>lower for performance

set_lower(lower=0)[source]#

Updating the distribution lower parameter. For Lognormal, even though we have a SciPy object, it’s not being used in the functions above for performance, so we need to update params directly.

dF_dtheta(x)#

Analytical derivatives of the Lognormal CDF w.r.t. μ and σ.

The CDF is F(x) = Φ((ln x - λ) / ζ) where ζ = sqrt(ln(1 + (σ/μ)²)) and λ = ln(μ) - ζ²/2.

The chain rule gives:

\[\frac{\partial F}{\partial \theta} = \frac{\varphi(z)}{\zeta} \left(-\frac{\partial\lambda}{\partial\theta} - z\,\frac{\partial\zeta}{\partial\theta}\right)\]

where z = (ln x - λ) / ζ.

jacobian(u, x)#

Diagonal Jacobian of the marginal x-to-u transformation.

Returns a diagonal matrix J where the diagonal entry is f_X(x) / phi(u) (Lemaire, eq. 4.9). This is assembled into the full Jacobian by the Transformation class.

Parameters:
  • u (float or array_like) – Value(s) in standard normal space.

  • x (float or array_like) – Corresponding value(s) in physical space.

Returns:

Diagonal Jacobian matrix of shape (n, n) where n is the length of the input arrays.

Return type:

ndarray

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

ppf(u)#

Percent-point function (inverse CDF).

Parameters:

u (float or array_like) – Probability value(s) in (0, 1).

Returns:

Quantile(s) in physical space.

Return type:

float or ndarray

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

set_location(loc=0)#

Updating the distribution location parameter. For Lognormal, even though we have a SciPy object, it’s not being used in the functions above for performance, so we need to update pe.arams directly.

set_scale(scale=1)#

Updating the distribution scale parameter. For Lognormal, even though we have a SciPy object, it’s not being used in the functions above for performance, so we need to update params directly.