Normal¶

class
probnum.random_variables.
Normal
(mean: Union[float, numpy.floating, numpy.ndarray, probnum.linops.LinearOperator], cov: Union[float, numpy.floating, numpy.ndarray, probnum.linops.LinearOperator], cov_cholesky: Union[numpy.ndarray, probnum.linops.LinearOperator, None] = None, random_state: Union[None, int, numpy.random.mtrand.RandomState, numpy.random._generator.Generator] = None)¶ Bases:
probnum.random_variables.ContinuousRandomVariable
The normal distribution.
The Gaussian distribution is ubiquitous in probability theory, since it is the final and stable or equilibrium distribution to which other distributions gravitate under a wide variety of smooth operations, e.g., convolutions and stochastic transformations. One example of this is the central limit theorem. The Gaussian distribution is also attractive from a numerical point of view as it is maintained through many transformations (e.g. it is stable).
Parameters:  mean (float or arraylike or LinearOperator) – Mean of the normal distribution.
 cov (float or arraylike or LinearOperator) – (Co)variance of the normal distribution.
 random_state (None or int or
RandomState
instance, optional) – This parameter defines the RandomState object to use for drawing realizations from this distribution. Think of it like a random seed. If None (or np.random), the global np.random state is used. If integer, it is used to seed the localRandomState
instance. Default is None.
See also
Distribution
 Class representing general probability distributions.
Examples
>>> from probnum import random_variables as rvs >>> N = rvs.Normal(mean=0.5, cov=1.0) >>> N.parameters {'mean': 0.5, 'cov': 1.0}
Attributes Summary
T
Transpose the random variable. cov
Covariance \(\operatorname{Cov}(X) = \mathbb{E}((X\mathbb{E}(X))(X\mathbb{E}(X))^\top)\) of the random variable. cov_cholesky
dense_cov
dense_mean
dtype
Data type of (elements of) a realization of this random variable. entropy
mean
Mean \(\mathbb{E}(X)\) of the distribution. median
Median of the random variable. median_dtype
The dtype of the median
.mode
Mode of the random variable. moment_dtype
The dtype of any (function of a) moment of the random variable, e.g. ndim
parameters
Parameters of the probability distribution. random_state
Random state of the random variable. shape
Shape of realizations of the random variable. size
std
Standard deviation of the distribution. var
Variance \(\operatorname{Var}(X) = \mathbb{E}((X\mathbb{E}(X))^2)\) of the distribution. Methods Summary
cdf
(x)Cumulative distribution function. dense_cov_cholesky
()in_support
(x)infer_median_dtype
(value_dtype, str])infer_moment_dtype
(value_dtype, str])logcdf
(x)Logcumulative distribution function. logpdf
(x)Natural logarithm of the probability density function. pdf
(x)Probability density or mass function. quantile
(p)Quantile function. reshape
(newshape, Iterable[numbers.Integral]])Give a new shape to a random variable. sample
(size, Iterable[numbers.Integral]] = ())Draw realizations from a random variable. transpose
(*axes)Transpose the random variable. Attributes Documentation

T
¶ Transpose the random variable.
Parameters: axes (None, tuple of ints, or n ints) – See documentation of numpy.ndarray.transpose. Returns: transposed_rv Return type: The transposed random variable.

cov
¶ Covariance \(\operatorname{Cov}(X) = \mathbb{E}((X\mathbb{E}(X))(X\mathbb{E}(X))^\top)\) of the random variable.
To learn about the dtype of the covariance, see
moment_dtype
.Returns: cov – The kernels of the random variable. Return type: arraylike

cov_cholesky
¶

dense_cov
¶

dense_mean
¶

dtype
¶ Data type of (elements of) a realization of this random variable.

entropy
¶

mean
¶ Mean \(\mathbb{E}(X)\) of the distribution.
To learn about the dtype of the mean, see
moment_dtype
.Returns: mean – The mean of the distribution. Return type: arraylike

median
¶ Median of the random variable.
To learn about the dtype of the median, see
median_dtype
.Returns: median – The median of the distribution. Return type: float

median_dtype
¶ The dtype of the
median
. It will be set to the dtype arising from the multiplication of values with dtypesdtype
andnp.float_
. This is motivated by the fact that, even for discrete random variables, e.g. integervalued random variables, themedian
might lie in between two values in which case these values are averaged. For example, a uniform random variable on \(\{ 1, 2, 3, 4 \}\) will have a median of \(2.5\).

mode
¶ Mode of the random variable.
Returns: mode – The mode of the random variable. Return type: float

moment_dtype
¶ The dtype of any (function of a) moment of the random variable, e.g. its
mean
,cov
,var
, orstd
. It will be set to the dtype arising from the multiplication of values with dtypesdtype
andnp.float_
. This is motivated by the mathematical definition of a moment as a sum or an integral over products of probabilities and values of the random variable, which are represented as using the dtypesnp.float_
anddtype
, respectively.

ndim
¶

parameters
¶ Parameters of the probability distribution.
The parameters of the distribution such as mean, variance, et cetera stored in a
dict
.

random_state
¶ Random state of the random variable.
This attribute defines the RandomState object to use for drawing realizations from this random variable. If None (or np.random), the global np.random state is used. If integer, it is used to seed the local
RandomState
instance.

shape
¶ Shape of realizations of the random variable.

size
¶

std
¶ Standard deviation of the distribution.
To learn about the dtype of the standard deviation, see
moment_dtype
.Returns: std – The standard deviation of the distribution. Return type: arraylike

var
¶ Variance \(\operatorname{Var}(X) = \mathbb{E}((X\mathbb{E}(X))^2)\) of the distribution.
To learn about the dtype of the variance, see
moment_dtype
.Returns: var – The variance of the distribution. Return type: arraylike
Methods Documentation

cdf
(x: ValueType) → numpy.float64¶ Cumulative distribution function.
Parameters: x (arraylike) – Evaluation points of the cumulative distribution function. The shape of this argument should be (..., S1, ..., SN)
, where(S1, ..., SN)
is theshape
of the random variable. The cdf evaluation will be broadcast over all additional dimensions.Returns: q – Value of the cumulative density function at the given points. Return type: arraylike

in_support
(x: ValueType) → bool¶

static
infer_median_dtype
(value_dtype: Union[numpy.dtype, str]) → numpy.dtype¶

static
infer_moment_dtype
(value_dtype: Union[numpy.dtype, str]) → numpy.dtype¶

logcdf
(x: ValueType) → numpy.float64¶ Logcumulative distribution function.
Parameters: x (arraylike) – Evaluation points of the cumulative distribution function. The shape of this argument should be (..., S1, ..., SN)
, where(S1, ..., SN)
is theshape
of the random variable. The logcdf evaluation will be broadcast over all additional dimensions.Returns: q – Value of the logcumulative density function at the given points. Return type: arraylike

logpdf
(x: ValueType) → numpy.float64¶ Natural logarithm of the probability density function.
Parameters: x (arraylike) – Evaluation points of the logprobability density/mass function. The shape of this argument should be (..., S1, ..., SN)
, where(S1, ..., SN)
is theshape
of the random variable. The logpdf evaluation will be broadcast over all additional dimensions.Returns: logp – Value of the logprobability density / mass function at the given points. Return type: arraylike

pdf
(x: ValueType) → numpy.float64¶ Probability density or mass function.
Following the predominant convention in mathematics, we express pdfs with respect to the Lebesgue measure unless stated otherwise.
Parameters: x (arraylike) – Evaluation points of the probability density / mass function. The shape of this argument should be (..., S1, ..., SN)
, where(S1, ..., SN)
is theshape
of the random variable. The pdf evaluation will be broadcast over all additional dimensions.Returns: p – Value of the probability density / mass function at the given points. Return type: arraylike

quantile
(p: numbers.Real) → ValueType¶ Quantile function.
The quantile function \(Q \colon [0, 1] \to \mathbb{R}\) of a random variable \(X\) is defined as \(Q(p) = \inf\{ x \in \mathbb{R} \colon p \le F_X(x) \}\), where \(F_X \colon \mathbb{R} \to [0, 1]\) is the
cdf()
of the random variable. From the definition it follows that the quantile function always returns values of the same dtype as the random variable. For instance, for a discrete distribution over the integers, the returned quantiles will also be integers. This means that, in general, \(Q(0.5)\) is not equal to themedian
as it is defined in this class. See https://en.wikipedia.org/wiki/Quantile_function for more details and examples.

reshape
(newshape: Union[numbers.Integral, Iterable[numbers.Integral]]) → probnum.random_variables.Normal[source]¶ Give a new shape to a random variable.
Parameters: newshape (int or tuple of ints) – New shape for the random variable. It must be compatible with the original shape. Returns: reshaped_rv Return type: self
with the new dimensions ofshape
.

sample
(size: Union[numbers.Integral, Iterable[numbers.Integral]] = ()) → ValueType¶ Draw realizations from a random variable.
Parameters: size (tuple) – Size of the drawn sample of realizations. Returns: sample – Sample of realizations with the given size
and the inherentshape
.Return type: arraylike