pyuncertainnumber.pba.distributions¶
Attributes¶
Classes¶
Two signatures are currentlly supported, either a parametric specification or from a nonparametric empirical data set. |
|
Joint distribution class |
|
Empirical cumulative distribution function (ecdf) class |
|
Functions¶
|
|
|
The sane lognormal which creates a lognormal distribution object based on the mean (mu) and standard deviation (sigma) |
|
Sane exponential distribution constructor |
Module Contents¶
- class pyuncertainnumber.pba.distributions.Distribution¶
Bases:
pyuncertainnumber.pba.mixins.NominalValueMixinTwo signatures are currentlly supported, either a parametric specification or from a nonparametric empirical data set.
Note
the nonparametric instasntiation via arrtribute empirical_data will be deprecated soon. We have introduced a
distributions.ECDFclass instead.Example
>>> d = Distribution('gaussian', (0,1))
- dist_family: str = None¶
- dist_params: list[float] | tuple[float, Ellipsis] = None¶
- empirical_data: list[float] | numpy.ndarray = None¶
- skip_post: bool = False¶
- __post_init__()¶
- __repr__()¶
- rep()¶
Create the underling dist object either sps dist or sample approximated or pbox dist
Note
underlying constructor to create the scipy.stats distribution object
- _match_distribution()¶
match the distribution object based on the family and parameters
- parse_params_from_dist()¶
- flag()¶
boolean flag for if the distribution is a parameterised distribution or not .. note:
- only parameterised dist can do sampling - for non-parameterised sample-data based dist, next steps could be fitting
- sample(size)¶
generate deviates from the distribution
- generate_rns(N)¶
generate ‘N’ random numbers from the distribution
- alpha_cut(alpha)¶
alpha cut interface
- make_nominal_value()¶
one value representation of the distribution .. note:: - use mean for now;
- plot(**kwargs)¶
display the distribution
- display(**kwargs)¶
- _get_hint()¶
- fit(data)¶
fit the distribution to the data
- get_PI(alpha: numbers.Number = 0.95) pyuncertainnumber.Interval¶
Compute the predictive interval at the coverage level of alpha
- Parameters:
alpha (-) – coverage level, default is 0.95
Example
>>> from pyuncertainnumber import pba >>> d = pba.Distribution('gaussian', (0, 1)) >>> pi = d.get_PI(alpha=0.95) >>> print(pi) # prints the interval at the 95% coverage level
- pdf(x: numpy.typing.ArrayLike)¶
compute the probability density function (pdf) at x
- log_pdf_eval(x: numpy.typing.ArrayLike)¶
compute the log of probability density function (pdf) at x
- cdf(x: numpy.typing.ArrayLike)¶
compute the cumulative distribution function (cdf) at x
- get_whole_cdf()¶
return the cumulative distribution function (cdf)
- _compute_nominal_value()¶
- property dist¶
the underlying sps.dist object
- property lo¶
- property hi¶
- property range¶
- property hint¶
- classmethod dist_from_sps(dist: scipy.stats.rv_continuous | scipy.stats.rv_discrete, shape: str = None)¶
- to_pbox()¶
convert the distribution to a pbox .. note:
- this only works for parameteried distributions for now - later on work with sample-approximated dist until `fit()`is implemented
- __neg__()¶
- __add__(other)¶
- __radd__(other)¶
- __sub__(other)¶
- __rsub__(other)¶
- __mul__(other)¶
- __rmul__(other)¶
- __truediv__(other)¶
- __rtruediv__(other)¶
- __pow__(other)¶
- __rpow__(other)¶
- class pyuncertainnumber.pba.distributions.JointDistribution(copula: pyuncertainnumber.pba.dependency.Dependency, marginals: list[Distribution])¶
Joint distribution class
Example
>>> from pyuncertainnumber import pba >>> dist_a, dist_b = pba.Distribution('gaussian', (5,1)), pba.Distribution('uniform', (2, 3)) >>> c = pba.Dependency('gaussian', params=0.8) >>> joint_dist = pba.JointDistribution(copula=c, marginals=[dist_a, dist_b]) >>> samples = joint_dist.sample(size=1000)
- marginals¶
- copula¶
- _joint_dist¶
- ndim¶
- __repr__()¶
- static from_sps(copula: statsmodels.distributions.copula, marginals: list[scipy.stats.rv_continuous])¶
- sample(size, random_state=42)¶
generate orginal-space samples from the joint distribution
- u_sample(size, random_state=42)¶
generate copula-space samples from the joint distribution
- joint_density_of_bi_grid(x: numpy.typing.ArrayLike, y: numpy.typing.ArrayLike)¶
compute the joint density on a grid given x and y arrays
Used for bivariate arithmetic calculations of X and Y with designated (known) dependency and marginals.
Note
discretisation step sizes dx and dy are set up by the input x and y arrays
Example
>>> x = np.linspace(0, 1, 50) >>> y = np.linspace(0, 1, 50) >>> dep = Dependency("gaussian", params=0.7) >>> joint_density = dep.joint_density_of_grid(x, y)
- static cdf_of_g(XX, YY, fXY, dx, dy, g_func, z_vals) numpy.typing.ArrayLike¶
Numerically approximate F_Z(z) = P(g(X,Y) <= z) via discretisation on a grid
- Parameters:
z_vals (ArrayLike) – discretisation of z values (array) at which to compute F_Z
XX – the grid arrays from meshgrid
YY – the grid arrays from meshgrid
fXY – joint density on the grid
dx – spacings in x and y directions
dy – spacings in x and y directions
g_func (callable) – a general callable applied elementwise to (XX, YY)
- Returns:
cumulative distribution function values at z_vals
- Return type:
FZ (ArrayLike)
Note
given precomputed grid (XX,YY), joint density fXY, and spacings.
- class pyuncertainnumber.pba.distributions.ECDF(empirical_data: numpy.ndarray)¶
Bases:
pyuncertainnumber.pba.pbox_abc.StaircaseEmpirical cumulative distribution function (ecdf) class
Implementation
supported by Pbox API hence samples will be degenerate intervals
Example
>>> import numpy as np >>> s = np.random.normal(size=1000) >>> ecdf = ECDF(s) >>> ecdf.plot()
- pyuncertainnumber.pba.distributions.uniform_sane(a, b)¶
- pyuncertainnumber.pba.distributions.lognormal_sane(mu, sigma)¶
The sane lognormal which creates a lognormal distribution object based on the mean (mu) and standard deviation (sigma) of the underlying normal distribution.
- Parameters:
mu (-) – Mean of the underlying normal distribution
sigma (-) – Standard deviation of the underlying normal distribution
- Returns:
A scipy.stats.lognorm frozen distribution object
- class pyuncertainnumber.pba.distributions.LognormalSaneDist¶
- ppf(p_values, *params)¶
- stats(*params, moments='mv')¶
- pyuncertainnumber.pba.distributions.expon_sane(lamb)¶
Sane exponential distribution constructor
- pyuncertainnumber.pba.distributions.named_dists¶