aspartik.stats.distributions
class Continuous:
runtime_checkable class Continuous(Protocol): """ A continuous statistical distribution In practice this defines the `pdf` and `ln_pdf` methods. """ def pdf(self, x: float) -> float: """ Probability density function May throw an exception if `x` is outside of support. """ ... def ln_pdf(self, x: float) -> float: """ Logarithm of a probability density function Some implementations might be more precise than calculating a logarithm on the result of the `pdf` method. """ ...#
A continuous statistical distribution
In practice this defines the pdf and ln_pdf methods.
def pdf(self, x: float) -> float
def pdf(self, x: float) -> float: """ Probability density function May throw an exception if `x` is outside of support. """ ...#
Probability density function
May throw an exception if x is outside of support.
def ln_pdf(self, x: float) -> float
def ln_pdf(self, x: float) -> float: """ Logarithm of a probability density function Some implementations might be more precise than calculating a logarithm on the result of the `pdf` method. """ ...#
Logarithm of a probability density function
Some implementations might be more precise than calculating a logarithm
on the result of the pdf method.
class ContinuousCDF:
runtime_checkable class ContinuousCDF(Continuous, Protocol): """ Density-related continuous distribution methods Also includes `lower` and `upper` properties, which define the interval on which the distribution is defined. """ def cdf(self, x: float) -> float: """ Continuous distribution function This method might throw an exception if `x` is outside of the supported interval. """ ... def sf(self, x: float) -> float: """Survival function""" ... def inverse_cdf(self, p: float) -> float: """ Inverse continuous distribution function `p` must be in the interval `[0, 1]`. """ ... property def lower(self) -> float: """ Lower bound of support `-inf` for distributions defined on all real numbers. """ ... property def upper(self) -> float: """ Upper bound of support Will be `+inf` for distributions defined on the entire line or on all positive reals. """ ...#
Density-related continuous distribution methods
Also includes lower and upper properties, which define the interval on
which the distribution is defined.
lower: float
property def lower(self) -> float: """ Lower bound of support `-inf` for distributions defined on all real numbers. """ ...#
Lower bound of support
-inf for distributions defined on all real numbers.
upper: float
property def upper(self) -> float: """ Upper bound of support Will be `+inf` for distributions defined on the entire line or on all positive reals. """ ...#
Upper bound of support
Will be +inf for distributions defined on the entire line or on all
positive reals.
def cdf(self, x: float) -> float
def cdf(self, x: float) -> float: """ Continuous distribution function This method might throw an exception if `x` is outside of the supported interval. """ ...#
Continuous distribution function
This method might throw an exception if x is outside of the supported
interval.
def sf(self, x: float) -> float
def sf(self, x: float) -> float: """Survival function""" ...#
Survival function
def inverse_cdf(self, p: float) -> float
def inverse_cdf(self, p: float) -> float: """ Inverse continuous distribution function `p` must be in the interval `[0, 1]`. """ ...#
Inverse continuous distribution function
p must be in the interval [0, 1].
def pdf(self, x: float) -> float
def pdf(self, x: float) -> float: """ Probability density function May throw an exception if `x` is outside of support. """ ...#
Probability density function
May throw an exception if x is outside of support.
def ln_pdf(self, x: float) -> float
def ln_pdf(self, x: float) -> float: """ Logarithm of a probability density function Some implementations might be more precise than calculating a logarithm on the result of the `pdf` method. """ ...#
Logarithm of a probability density function
Some implementations might be more precise than calculating a logarithm
on the result of the pdf method.
class Discrete:
runtime_checkable class Discrete[T](Protocol): def pmf(self, x: T) -> float: ... def ln_pmf(self, x: T) -> float: ...#
Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
def meth(self) -> int:
...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
class C:
def meth(self) -> int:
return 0
def func(x: Proto) -> int:
return x.meth()
func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::
class GenProto[T](Protocol):
def meth(self) -> T:
...
def pmf(self, x: T) -> float
def pmf(self, x: T) -> float: ...#
def ln_pmf(self, x: T) -> float
def ln_pmf(self, x: T) -> float: ...#
class DiscreteCDF:
runtime_checkable class DiscreteCDF[T](Discrete[T], Protocol): def cdf(self, x: T) -> float: ... def sf(self, x: T) -> float: ... def inverse_cdf(self, p: float) -> T: ... property def lower(self) -> T: ... property def upper(self) -> T: ...#
Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
def meth(self) -> int:
...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
class C:
def meth(self) -> int:
return 0
def func(x: Proto) -> int:
return x.meth()
func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::
class GenProto[T](Protocol):
def meth(self) -> T:
...
lower
property def lower(self) -> T: ...#
upper
property def upper(self) -> T: ...#
def cdf(self, x: T) -> float
def cdf(self, x: T) -> float: ...#
def sf(self, x: T) -> float
def sf(self, x: T) -> float: ...#
def inverse_cdf(self, p: float) -> T
def inverse_cdf(self, p: float) -> T: ...#
def pmf(self, x: T) -> float
def pmf(self, x: T) -> float: ...#
def ln_pmf(self, x: T) -> float
def ln_pmf(self, x: T) -> float: ...#
class Distribution:
runtime_checkable class Distribution(Protocol): def mean(self) -> Optional[float]: ... def median(self) -> Optional[float]: ... def variance(self) -> Optional[float]: ... def std_dev(self) -> Optional[float]: ... def entropy(self) -> Optional[float]: ... def skewness(self) -> Optional[float]: ...#
Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
def meth(self) -> int:
...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
class C:
def meth(self) -> int:
return 0
def func(x: Proto) -> int:
return x.meth()
func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::
class GenProto[T](Protocol):
def meth(self) -> T:
...
def mean(self) -> Optional[float]
def mean(self) -> Optional[float]: ...#
def median(self) -> Optional[float]
def median(self) -> Optional[float]: ...#
def variance(self) -> Optional[float]
def variance(self) -> Optional[float]: ...#
def std_dev(self) -> Optional[float]
def std_dev(self) -> Optional[float]: ...#
def entropy(self) -> Optional[float]
def entropy(self) -> Optional[float]: ...#
def skewness(self) -> Optional[float]
def skewness(self) -> Optional[float]: ...#
class Sample:
runtime_checkable class Sample[T](Protocol): def sample(self, rng: RNG) -> T: ...#
Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
def meth(self) -> int:
...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
class C:
def meth(self) -> int:
return 0
def func(x: Proto) -> int:
return x.meth()
func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::
class GenProto[T](Protocol):
def meth(self) -> T:
...
def sample(self, rng: aspartik.rng.RNG) -> T
def sample(self, rng: RNG) -> T: ...#
class Beta:
#Examples
use stats::distribution::{Beta, Continuous};
use stats::statistics::*;
use math::assert_almost_eq;
let n = Beta::new(2.0, 2.0).unwrap();
assert_eq!(n.mean().unwrap(), 0.5);
assert_almost_eq!(n.pdf(0.5), 1.5, epsilon = 1e-14);
shape_a
#lower
#upper
#shape_b
#def pdf(self, /, x)
#def ln_pdf(self, /, x)
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#def sample(self, /, rng)
#class BetaError:
#class Exp:
#Implements the Exp distribution and is a special case of the Gamma distribution (referenced here)
Examples
use stats::distribution::{Exp, Continuous};
use stats::statistics::Distribution;
let n = Exp::new(1.0).unwrap();
assert_eq!(n.mean().unwrap(), 1.0);
assert_eq!(n.pdf(1.0), 0.36787944117144233);
upper
#rate
#lower
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#def sample(self, /, rng)
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#def pdf(self, /, x)
#def ln_pdf(self, /, x)
#class ExpError:
#Represents the errors that can occur when creating a [Exp].
RateInvalid
#class Gamma:
#Implements the Gamma distribution
Examples
use stats::distribution::{Gamma, Continuous};
use stats::statistics::Distribution;
use math::assert_almost_eq;
let n = Gamma::new(3.0, 1.0).unwrap();
assert_eq!(n.mean().unwrap(), 3.0);
assert_almost_eq!(n.pdf(2.0), 0.2706705664732254, epsilon = 1e-15);
lower
#rate
#shape
#upper
#def pdf(self, /, x)
#def ln_pdf(self, /, x)
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#def sample(self, /, rng)
#class GammaError:
#class InverseGamma:
#Implements the Inverse Gamma distribution
Examples
use stats::distribution::{InverseGamma, Continuous};
use stats::statistics::Distribution;
use math::assert_almost_eq;
let n = InverseGamma::new(1.1, 0.1).unwrap();
assert_almost_eq!(n.mean().unwrap(), 1.0, epsilon = 1e-14);
assert_eq!(n.pdf(1.0), 0.07554920138253064);
lower
#rate
#shape
#upper
#def pdf(self, /, x)
#def ln_pdf(self, /, x)
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#def sample(self, /, rng)
#class InverseGammaError:
#class Laplace:
#Implements the Laplace distribution.
Examples
use stats::distribution::{Laplace, Continuous};
use stats::statistics::Mode;
let n = Laplace::new(0.0, 1.0).unwrap();
assert_eq!(n.mode().unwrap(), 0.0);
assert_eq!(n.pdf(1.0), 0.18393972058572117);
lower
#scale
#location
#upper
#def pdf(self, /, x)
#def ln_pdf(self, /, x)
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#def sample(self, /, rng)
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#class LaplaceError:
#class LogNormal:
#Implements the Log-normal distribution
Examples
use stats::distribution::{LogNormal, Continuous};
use stats::statistics::Distribution;
use math::assert_almost_eq;
let n = LogNormal::new(0.0, 1.0).unwrap();
assert_eq!(n.mean().unwrap(), (0.5f64).exp());
assert_almost_eq!(n.pdf(1.0), 0.3989422804014327, epsilon = 1e-16);
upper
#scale
#lower
#location
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#def pdf(self, /, x)
#def ln_pdf(self, /, x)
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#def sample(self, /, rng)
#class LogNormalError:
#class Normal:
#Implements the Normal distribution
Examples
use stats::distribution::{Normal, Continuous};
use stats::statistics::Distribution;
let n = Normal::new(0.0, 1.0).unwrap();
assert_eq!(n.mean().unwrap(), 0.0);
assert_eq!(n.pdf(1.0), 0.24197072451914334);
lower
#upper
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#def sample(self, /, rng)
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#def pdf(self, /, x)
#def ln_pdf(self, /, x)
#class NormalError:
#class Poisson:
#Implements the Poisson distribution
Examples
use stats::distribution::{Poisson, Discrete};
use stats::statistics::Distribution;
use math::assert_almost_eq;
let n = Poisson::new(1.0).unwrap();
assert_eq!(n.mean().unwrap(), 1.0);
assert_almost_eq!(n.pmf(1), 0.367879441171442, epsilon = 1e-15);
lambda_
#lower
#upper
#def pmf(self, /, x)
#def ln_pmf(self, /, x)
#def mean(self, /)
#def median(self, /)
#def variance(self, /)
#def std_dev(self, /)
#def entropy(self, /)
#def skewness(self, /)
#def cdf(self, /, x)
#def sf(self, /, x)
#def inverse_cdf(self, /, p)
#class PoissonError:
#Represents the errors that can occur when creating a [Poisson].
LambdaInvalid
#class Uniform:
#Implements the Continuous Uniform distribution
Examples
use stats::distribution::{Uniform, Continuous};
use stats::statistics::Distribution;
let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!(n.mean().unwrap(), 0.5);
assert_eq!(n.pdf(0.5), 1.0);