from multinorm import MultiNorm mean = [10, 20, 30] covariance = [[1, 0, 0], [0, 4, 0], [0, 0, 9]] names = ["a", "b", "c"] mn = MultiNorm(mean, covariance, names)
But where do these things come from?
On this page, we look at the most common scenarios.
Create from fit¶
TODO: show example using
multinorm, we first need to fit some parameterised model
to obtain a best-fit parameter vector and covariance matrix.
scipy.optimize.curve_fit to fit some data.
TODO: show example using iminuit
http://www.statsmodels.org/devel/examples/notebooks/generated/chi2_fitting.html https://github.com/cdeil/pyfit/blob/master/fitting_tutorial/src/tests/chi2_example.py https://lmfit.github.io https://iminuit.readthedocs.io https://sherpa.readthedocs.io
Create from publication¶
TODO: show example how to take covar (or par errors) from a publication or blog post, i.e. as inputs.
Create from samples¶
A common way to analyse likelihood or in Bayesian analyses the posterior probability distributions is to use MCMC methods that sample the distribution. E.g. emcee or pymc are Python packages that generate this kind of output.
Estimating the multivariate normal distribution from samples well can be difficult, there are many methods with different trade-offs. We recommend using a different package for this task, e.g. sklearn.covariance.
Samples should always be given as 2-dimensional arrays with shape
>>> samples = mn.sample(size=100, random_state=0) >>> MultiNorm.from_samples(samples, names=mn.names) MultiNorm with n=3 parameters: mean error name a 9.875816 0.980901 b 20.212505 1.973948 c 30.301562 3.093609