API¶
-
class
multinorm.MultiNorm(mean=None, cov=None, names=None)[source]¶ Multivariate normal distribution.
Given
nparameters, themeanandnamesshould be one-dimensional with sizen, andcovshould be a two-dimensional matrix of shape(n, n).Documentation for this class:
- Tutorial Jupyter notebook: multinorm.ipynb
- Documentation: Getting started, Create, Analyse
- Equations and statistics: Theory
Note that MultiNorm objects should be used read-only, almost all properties are cached. If you need to modify values, make a new MultiNorm object.
Parameters: - mean (numpy.ndarray) – Mean vector
- cov (numpy.ndarray) – Covariance matrix
- names (list) – Python list of parameter names (str).
Default: use “par_i” with
i = 0 .. N - 1.
-
conditional(pars, values=None)[source]¶ Conditional MultiNormal distribution.
Resulting lower-dimensional distribution obtained by fixing
parstovalues. The output distribution is for the other parameters, the complement ofpars.Parameters: Returns: MultiNorm – Conditional distribution
-
correlation¶ Correlation matrix (pandas.DataFrame).
Correlation \(C\) is related to covariance \(\Sigma\) via:
\[C_{ij} = \frac{ \Sigma_{ij} }{ \sqrt{\Sigma_{ii} \Sigma_{jj}} }\]
-
cov¶ Covariance matrix (pandas.DataFrame).
-
drop(pars)[source]¶ Drop parameters.
This simply removes the entry from the mean vector, and the corresponding column and row from the cov matrix.
The computation is the same as
MultiNorm.marginal(), only here the parameters to drop are given, and there the parameters to keep are given.Parameters: pars (list) – Parameters to fix (indices or names)
-
err¶ Error vector (pandas.DataFrame).
Defined as \(\sigma_i = \sqrt{\Sigma_{ii}}\).
-
fix(pars)[source]¶ Fix parameters.
See Fix parameters.
Parameters: pars (list) – Parameters to fix (indices or names)
-
classmethod
from_err(mean=None, err=None, correlation=None, names=None)[source]¶ Create MultiNorm from parameter errors.
With errors \(\sigma_i\) this will create a diagonal covariance matrix with
\[\Sigma_{ii} = \sigma_i^2\]For a given
correlation, or in general: this will create a MultiNormal with a covariance matrix such that it’serrandcorrelationmatch the one specified here (up to rounding errors).Parameters: - mean (numpy.ndarray) – Mean vector
- err (numpy.ndarray) – Error vector
- correlation (numpy.ndarray) – Correlation matrix
- names (list) – Parameter names
-
classmethod
from_points(points, names=None)[source]¶ Create MultiNorm from parameter points.
Usually the points are samples from some distribution and creating this MultiNorm distribution is an estimate / approximation of that distribution of interest.
See: From points.
Parameters: points (numpy.ndarray) – Array of data points with shape (n, 2).
-
classmethod
from_product(distributions)[source]¶ Create MultiNorm as product distribution.
This represents the joint likelihood distribution, assuming the individual distributions are from independent measurements.
See Product distribution .
Parameters: distributions (list) – Python list of MultiNorm distributions. Returns: MultiNorm – Product distribution
-
classmethod
make_example(n_par=3, n_fix=0, random_state=42)[source]¶ Create example MultiNorm for testing.
This is a factory method that allows the quick creation of example MultiNormal with any number of parameters for testing.
See: Make example.
Parameters:
-
marginal(pars)[source]¶ Marginal MultiNormal distribution.
Parameters: pars (list) – List of parameters (integer indices) Returns: MultiNorm – Marginal distribution
-
mean¶ Mean vector (pandas.Series).
-
n¶ Number of dimensions of the distribution (int).
Given by the number of parameters.
-
names¶ Parameter names (list of str).
-
parameters¶ Parameter table (pandas.DataFrame).
Index is “name”, columns are “mean” and “err”
-
precision¶ Precision matrix (pandas.DataFrame).
The inverse of the covariance matrix.
Sometimes called the “information matrix” or “Hesse matrix”.
-
scipy¶ Frozen scipy.stats.multivariate_normal distribution object.
A cached property. Used for many computations internally.
-
sigma_distance(point)[source]¶ Number of standard deviations from the mean (float).
Also called the Mahalanobis distance. See Sigmas.
-
to_matplotlib_ellipse(n_sigma=1, **kwargs)[source]¶ Create matplotlib.patches.Ellipse.
See examples in Plot.
Parameters: n_sigma (int) – Number of standard deviations. See Sigmas.
-
to_uncertainties()[source]¶ Convert to uncertainties objects.
A tuple of numbers with uncertainties (one for each parameter) is returned.
The uncertainties package makes it easy to do error propagation on derived quantities.
See examples in Analyse.