ism3d.maths.stats.laplace_gen

class ism3d.maths.stats.laplace_gen(momtype=1, a=None, b=None, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None, seed=None)[source]

Bases: scipy.stats._distn_infrastructure.rv_continuous

rho Distribution of a axisymatteric 2D distribution with a Exponential radial profile

Methods

cdf

Cumulative distribution function of the given RV.

entropy

Differential entropy of the RV.

expect

Calculate expected value of a function with respect to the distribution by numerical integration.

fit

Return MLEs for shape (if applicable), location, and scale parameters from data.

fit_loc_scale

Estimate loc and scale parameters from data using 1st and 2nd moments.

freeze

Freeze the distribution for the given arguments.

interval

Confidence interval with equal areas around the median.

isf

Inverse survival function (inverse of sf) at q of the given RV.

logcdf

Log of the cumulative distribution function at x of the given RV.

logpdf

Log of the probability density function at x of the given RV.

logsf

Log of the survival function of the given RV.

mean

Mean of the distribution.

median

Median of the distribution.

moment

n-th order non-central moment of distribution.

nnlf

Return negative loglikelihood function.

pdf

Probability density function at x of the given RV.

ppf

Percent point function (inverse of cdf) at q of the given RV.

rvs

Random variates of given type.

sf

Survival function (1 - cdf) at x of the given RV.

stats

Some statistics of the given RV.

std

Standard deviation of the distribution.

support

Return the support of the distribution.

var

Variance of the distribution.

Attributes

random_state

Get or set the RandomState object for generating random variates.

__call__(*args, **kwds)

Freeze the distribution for the given arguments.

Parameters

arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution. Should include all the non-optional arguments, may include loc and scale.

Returns

rv_frozen – The frozen distribution.

Return type

rv_frozen instance

cdf(x, *args, **kwds)

Cumulative distribution function of the given RV.

Parameters
  • x (array_like) – quantiles

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

cdf – Cumulative distribution function evaluated at x

Return type

ndarray

entropy(*args, **kwds)

Differential entropy of the RV.

Parameters
  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information).

  • loc (array_like, optional) – Location parameter (default=0).

  • scale (array_like, optional (continuous distributions only).) – Scale parameter (default=1).

Notes

Entropy is defined base e:

>>> drv = rv_discrete(values=((0, 1), (0.5, 0.5)))
>>> np.allclose(drv.entropy(), np.log(2.0))
True
expect(func=None, args=(), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)

Calculate expected value of a function with respect to the distribution by numerical integration.

The expected value of a function f(x) with respect to a distribution dist is defined as:

        ub
E[f(x)] = Integral(f(x) * dist.pdf(x)),
        lb

where ub and lb are arguments and x has the dist.pdf(x) distribution. If the bounds lb and ub correspond to the support of the distribution, e.g. [-inf, inf] in the default case, then the integral is the unrestricted expectation of f(x). Also, the function f(x) may be defined such that f(x) is 0 outside a finite interval in which case the expectation is calculated within the finite range [lb, ub].

Parameters
  • func (callable, optional) – Function for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.

  • args (tuple, optional) – Shape parameters of the distribution.

  • loc (float, optional) – Location parameter (default=0).

  • scale (float, optional) – Scale parameter (default=1).

  • lb, ub (scalar, optional) – Lower and upper bound for integration. Default is set to the support of the distribution.

  • conditional (bool, optional) – If True, the integral is corrected by the conditional probability of the integration interval. The return value is the expectation of the function, conditional on being in the given interval. Default is False.

  • Additional keyword arguments are passed to the integration routine.

Returns

expect – The calculated expected value.

Return type

float

Notes

The integration behavior of this function is inherited from scipy.integrate.quad. Neither this function nor scipy.integrate.quad can verify whether the integral exists or is finite. For example cauchy(0).mean() returns np.nan and cauchy(0).expect() returns 0.0.

The function is not vectorized.

Examples

To understand the effect of the bounds of integration consider

>>> from scipy.stats import expon
>>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0)
0.6321205588285578

This is close to

>>> expon(1).cdf(2.0) - expon(1).cdf(0.0)
0.6321205588285577

If conditional=True

>>> expon(1).expect(lambda x: 1, lb=0.0, ub=2.0, conditional=True)
1.0000000000000002

The slight deviation from 1 is due to numerical integration.

fit(data, *args, **kwds)

Return MLEs for shape (if applicable), location, and scale parameters from data.

MLE stands for Maximum Likelihood Estimate. Starting estimates for the fit are given by input arguments; for any arguments not provided with starting estimates, self._fitstart(data) is called to generate such.

One can hold some parameters fixed to specific values by passing in keyword arguments f0, f1, …, fn (for shape parameters) and floc and fscale (for location and scale parameters, respectively).

Parameters
  • data (array_like) – Data to use in calculating the MLEs.

  • arg1, arg2, arg3,… (floats, optional) – Starting value(s) for any shape-characterizing arguments (those not provided will be determined by a call to _fitstart(data)). No default value.

  • kwds (floats, optional) –

    • loc: initial guess of the distribution’s location parameter.

    • scale: initial guess of the distribution’s scale parameter.

    Special keyword arguments are recognized as holding certain parameters fixed:

    • f0…fn : hold respective shape parameters fixed. Alternatively, shape parameters to fix can be specified by name. For example, if self.shapes == "a, b", fa and fix_a are equivalent to f0, and fb and fix_b are equivalent to f1.

    • floc : hold location parameter fixed to specified value.

    • fscale : hold scale parameter fixed to specified value.

    • optimizer : The optimizer to use. The optimizer must take func, and starting position as the first two arguments, plus args (for extra arguments to pass to the function to be optimized) and disp=0 to suppress output as keyword arguments.

Returns

mle_tuple – MLEs for any shape parameters (if applicable), followed by those for location and scale. For most random variables, shape statistics will be returned, but there are exceptions (e.g. norm).

Return type

tuple of floats

Notes

This fit is computed by maximizing a log-likelihood function, with penalty applied for samples outside of range of the distribution. The returned answer is not guaranteed to be the globally optimal MLE, it may only be locally optimal, or the optimization may fail altogether. If the data contain any of np.nan, np.inf, or -np.inf, the fit routine will throw a RuntimeError.

Examples

Generate some data to fit: draw random variates from the beta distribution

>>> from scipy.stats import beta
>>> a, b = 1., 2.
>>> x = beta.rvs(a, b, size=1000)

Now we can fit all four parameters (a, b, loc and scale):

>>> a1, b1, loc1, scale1 = beta.fit(x)

We can also use some prior knowledge about the dataset: let’s keep loc and scale fixed:

>>> a1, b1, loc1, scale1 = beta.fit(x, floc=0, fscale=1)
>>> loc1, scale1
(0, 1)

We can also keep shape parameters fixed by using f-keywords. To keep the zero-th shape parameter a equal 1, use f0=1 or, equivalently, fa=1:

>>> a1, b1, loc1, scale1 = beta.fit(x, fa=1, floc=0, fscale=1)
>>> a1
1

Not all distributions return estimates for the shape parameters. norm for example just returns estimates for location and scale:

>>> from scipy.stats import norm
>>> x = norm.rvs(a, b, size=1000, random_state=123)
>>> loc1, scale1 = norm.fit(x)
>>> loc1, scale1
(0.92087172783841631, 2.0015750750324668)
fit_loc_scale(data, *args)

Estimate loc and scale parameters from data using 1st and 2nd moments.

Parameters
  • data (array_like) – Data to fit.

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information).

Returns

  • Lhat (float) – Estimated location parameter for the data.

  • Shat (float) – Estimated scale parameter for the data.

freeze(*args, **kwds)

Freeze the distribution for the given arguments.

Parameters

arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution. Should include all the non-optional arguments, may include loc and scale.

Returns

rv_frozen – The frozen distribution.

Return type

rv_frozen instance

interval(alpha, *args, **kwds)

Confidence interval with equal areas around the median.

Parameters
  • alpha (array_like of float) – Probability that an rv will be drawn from the returned range. Each value should be in the range [0, 1].

  • arg1, arg2, … (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information).

  • loc (array_like, optional) – location parameter, Default is 0.

  • scale (array_like, optional) – scale parameter, Default is 1.

Returns

a, b – end-points of range that contain 100 * alpha % of the rv’s possible values.

Return type

ndarray of float

isf(q, *args, **kwds)

Inverse survival function (inverse of sf) at q of the given RV.

Parameters
  • q (array_like) – upper tail probability

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

x – Quantile corresponding to the upper tail probability q.

Return type

ndarray or scalar

logcdf(x, *args, **kwds)

Log of the cumulative distribution function at x of the given RV.

Parameters
  • x (array_like) – quantiles

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

logcdf – Log of the cumulative distribution function evaluated at x

Return type

array_like

logpdf(x, *args, **kwds)

Log of the probability density function at x of the given RV.

This uses a more numerically accurate calculation if available.

Parameters
  • x (array_like) – quantiles

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

logpdf – Log of the probability density function evaluated at x

Return type

array_like

logsf(x, *args, **kwds)

Log of the survival function of the given RV.

Returns the log of the “survival function,” defined as (1 - cdf), evaluated at x.

Parameters
  • x (array_like) – quantiles

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

logsf – Log of the survival function evaluated at x.

Return type

ndarray

mean(*args, **kwds)

Mean of the distribution.

Parameters
  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

mean – the mean of the distribution

Return type

float

median(*args, **kwds)

Median of the distribution.

Parameters
  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – Location parameter, Default is 0.

  • scale (array_like, optional) – Scale parameter, Default is 1.

Returns

median – The median of the distribution.

Return type

float

See also

rv_discrete.ppf()

Inverse of the CDF

moment(n, *args, **kwds)

n-th order non-central moment of distribution.

Parameters
  • n (int, n >= 1) – Order of moment.

  • arg1, arg2, arg3,… (float) – The shape parameter(s) for the distribution (see docstring of the instance object for more information).

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

nnlf(theta, x)

Return negative loglikelihood function.

Notes

This is -sum(log pdf(x, theta), axis=0) where theta are the parameters (including loc and scale).

pdf(x, *args, **kwds)

Probability density function at x of the given RV.

Parameters
  • x (array_like) – quantiles

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

pdf – Probability density function evaluated at x

Return type

ndarray

ppf(q, *args, **kwds)

Percent point function (inverse of cdf) at q of the given RV.

Parameters
  • q (array_like) – lower tail probability

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

x – quantile corresponding to the lower tail probability q.

Return type

array_like

property random_state

Get or set the RandomState object for generating random variates.

This can be either None, int, a RandomState instance, or a np.random.Generator instance.

If None (or np.random), use the RandomState singleton used by np.random. If already a RandomState or Generator instance, use it. If an int, use a new RandomState instance seeded with seed.

rvs(*args, **kwds)

Random variates of given type.

Parameters
  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information).

  • loc (array_like, optional) – Location parameter (default=0).

  • scale (array_like, optional) – Scale parameter (default=1).

  • size (int or tuple of ints, optional) – Defining number of random variates (default is 1).

  • random_state ({None, int, ~np.random.RandomState, ~np.random.Generator}, optional) – If seed is None the ~np.random.RandomState singleton is used. If seed is an int, a new RandomState instance is used, seeded with seed. If seed is already a RandomState or Generator instance, then that object is used. Default is None.

Returns

rvs – Random variates of given size.

Return type

ndarray or scalar

sf(x, *args, **kwds)

Survival function (1 - cdf) at x of the given RV.

Parameters
  • x (array_like) – quantiles

  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

sf – Survival function evaluated at x

Return type

array_like

stats(*args, **kwds)

Some statistics of the given RV.

Parameters
  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional (continuous RVs only)) – scale parameter (default=1)

  • moments (str, optional) – composed of letters [‘mvsk’] defining which moments to compute: ‘m’ = mean, ‘v’ = variance, ‘s’ = (Fisher’s) skew, ‘k’ = (Fisher’s) kurtosis. (default is ‘mv’)

Returns

stats – of requested moments.

Return type

sequence

std(*args, **kwds)

Standard deviation of the distribution.

Parameters
  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

std – standard deviation of the distribution

Return type

float

support(*args, **kwargs)

Return the support of the distribution.

Parameters
  • arg1, arg2, … (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information).

  • loc (array_like, optional) – location parameter, Default is 0.

  • scale (array_like, optional) – scale parameter, Default is 1.

Returns

a, b – end-points of the distribution’s support.

Return type

float

var(*args, **kwds)

Variance of the distribution.

Parameters
  • arg1, arg2, arg3,… (array_like) – The shape parameter(s) for the distribution (see docstring of the instance object for more information)

  • loc (array_like, optional) – location parameter (default=0)

  • scale (array_like, optional) – scale parameter (default=1)

Returns

var – the variance of the distribution

Return type

float