pyuncertainnumber.pba.distributions =================================== .. py:module:: pyuncertainnumber.pba.distributions Attributes ---------- .. autoapisummary:: pyuncertainnumber.pba.distributions.named_dists Classes ------- .. autoapisummary:: pyuncertainnumber.pba.distributions.Distribution pyuncertainnumber.pba.distributions.JointDistribution pyuncertainnumber.pba.distributions.ECDF pyuncertainnumber.pba.distributions.LognormalSaneDist pyuncertainnumber.pba.distributions.WrapperDist Functions --------- .. autoapisummary:: pyuncertainnumber.pba.distributions.uniform_sane pyuncertainnumber.pba.distributions.lognormal_sane pyuncertainnumber.pba.distributions.expon_sane Module Contents --------------- .. py:class:: Distribution Bases: :py:obj:`pyuncertainnumber.pba.mixins.NominalValueMixin` Two 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 :class:`distributions.ECDF` class instead. .. rubric:: Example >>> d = Distribution('gaussian', (0,1)) .. py:attribute:: dist_family :type: str :value: None .. py:attribute:: dist_params :type: list[float] | tuple[float, Ellipsis] :value: None .. py:attribute:: empirical_data :type: list[float] | numpy.ndarray :value: None .. py:attribute:: skip_post :type: bool :value: False .. py:method:: __post_init__() .. py:method:: __repr__() .. py:method:: 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 .. py:method:: _match_distribution() match the distribution object based on the family and parameters .. py:method:: parse_params_from_dist() .. py:method:: 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 .. py:method:: sample(size) generate deviates from the distribution .. py:method:: generate_rns(N) generate 'N' random numbers from the distribution .. py:method:: alpha_cut(alpha) alpha cut interface .. py:method:: make_nominal_value() one value representation of the distribution .. note:: - use mean for now; .. py:method:: plot(**kwargs) display the distribution .. py:method:: display(**kwargs) .. py:method:: _get_hint() .. py:method:: fit(data) fit the distribution to the data .. py:method:: get_PI(alpha: numbers.Number = 0.95) -> pyuncertainnumber.Interval Compute the predictive interval at the coverage level of `alpha` :param - alpha: coverage level, default is 0.95 :type - alpha: float .. rubric:: 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 .. py:method:: pdf(x: numpy.typing.ArrayLike) compute the probability density function (pdf) at x .. py:method:: log_pdf_eval(x: numpy.typing.ArrayLike) compute the log of probability density function (pdf) at x .. py:method:: cdf(x: numpy.typing.ArrayLike) compute the cumulative distribution function (cdf) at x .. py:method:: get_whole_cdf() return the cumulative distribution function (cdf) .. py:method:: _compute_nominal_value() .. py:property:: dist the underlying sps.dist object .. py:property:: lo .. py:property:: hi .. py:property:: range .. py:property:: hint .. py:method:: dist_from_sps(dist: scipy.stats.rv_continuous | scipy.stats.rv_discrete, shape: str = None) :classmethod: .. py:method:: 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 .. py:method:: __neg__() .. py:method:: __add__(other) .. py:method:: __radd__(other) .. py:method:: __sub__(other) .. py:method:: __rsub__(other) .. py:method:: __mul__(other) .. py:method:: __rmul__(other) .. py:method:: __truediv__(other) .. py:method:: __rtruediv__(other) .. py:method:: __pow__(other) .. py:method:: __rpow__(other) .. py:class:: JointDistribution(copula: pyuncertainnumber.pba.dependency.Dependency, marginals: list[Distribution]) Joint distribution class .. rubric:: 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) .. py:attribute:: marginals .. py:attribute:: copula .. py:attribute:: _joint_dist .. py:attribute:: ndim .. py:method:: __repr__() .. py:method:: from_sps(copula: statsmodels.distributions.copula, marginals: list[scipy.stats.rv_continuous]) :staticmethod: .. py:method:: sample(size, random_state=42) generate orginal-space samples from the joint distribution .. py:method:: u_sample(size, random_state=42) generate copula-space samples from the joint distribution .. py:method:: 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 .. rubric:: 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) .. py:method:: cdf_of_g(XX, YY, fXY, dx, dy, g_func, z_vals) -> numpy.typing.ArrayLike :staticmethod: Numerically approximate F_Z(z) = P(g(X,Y) <= z) via discretisation on a grid :param z_vals: discretisation of z values (array) at which to compute F_Z :type z_vals: ArrayLike :param XX: the grid arrays from meshgrid :param YY: the grid arrays from meshgrid :param fXY: joint density on the grid :param dx: spacings in x and y directions :param dy: spacings in x and y directions :param g_func: a general callable applied elementwise to (XX, YY) :type g_func: callable :returns: cumulative distribution function values at z_vals :rtype: FZ (ArrayLike) .. note:: given precomputed grid (XX,YY), joint density fXY, and spacings. .. py:class:: ECDF(empirical_data: numpy.ndarray) Bases: :py:obj:`pyuncertainnumber.pba.pbox_abc.Staircase` Empirical cumulative distribution function (ecdf) class .. admonition:: Implementation supported by `Pbox` API hence samples will be degenerate intervals .. rubric:: Example >>> import numpy as np >>> s = np.random.normal(size=1000) >>> ecdf = ECDF(s) >>> ecdf.plot() .. py:function:: uniform_sane(a, b) .. py:function:: 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. :param - mu: Mean of the underlying normal distribution :type - mu: float :param - sigma: Standard deviation of the underlying normal distribution :type - sigma: float :returns: - A scipy.stats.lognorm frozen distribution object .. py:class:: LognormalSaneDist .. py:method:: ppf(p_values, *params) .. py:method:: stats(*params, moments='mv') .. py:function:: expon_sane(lamb) Sane exponential distribution constructor .. py:class:: WrapperDist(ppf_func) .. py:attribute:: _ppf .. py:method:: ppf(*args, **kwargs) .. py:data:: named_dists