pystra.distributions.lognormal.Lognormal#
- class Lognormal(name, mean, stdv, input_type=None, startpoint=None)[source]#
Bases:
DistributionLognormal distribution
- Arguments:
name (str): Name of the random variable
mean (float): Mean or lamb
stdv (float): Standard deviation or zeta
input_type (any): Change meaning of mean and stdv
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
Cumulative distribution function
Analytical derivatives of the Lognormal CDF w.r.t.
getMeangetNamegetStartPointgetStdvDiagonal Jacobian of the marginal x-to-u transformation.
Probability density function Note: asssumes x>0 for performance, scipy manages this appropriately
Plot the probability density function.
Percent-point function (inverse CDF).
Draw random samples from the distribution.
setStartPointUpdating the distribution location parameter.
Updating the distribution scale parameter.
Transformation from u to x
Transformation from x to u Note: asssumes x>0 for performance
- pdf(x)[source]#
Probability density function Note: asssumes x>0 for performance, scipy manages this appropriately
- dF_dtheta(x)[source]#
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 - λ) / ζ.
- set_location(loc=0)[source]#
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)[source]#
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.
- jacobian(u, x)#
Diagonal Jacobian of the marginal x-to-u transformation.
Returns a diagonal matrix
Jwhere the diagonal entry isf_X(x) / phi(u)(Lemaire, eq. 4.9). This is assembled into the full Jacobian by theTransformationclass.- 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_kwargsbut not insensitivity_paramsare 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