# pymc.MvNormal#

class pymc.MvNormal(name, *args, rng=None, dims=None, initval=None, observed=None, total_size=None, transform=UNSET, **kwargs)[source]#

Multivariate normal log-likelihood.

$f(x \mid \pi, T) = \frac{|T|^{1/2}}{(2\pi)^{k/2}} \exp\left\{ -\frac{1}{2} (x-\mu)^{\prime} T (x-\mu) \right\}$
 Support $$x \in \mathbb{R}^k$$ Mean $$\mu$$ Variance $$T^{-1}$$
Parameters
mu

Vector of means.

covtensor_like of float, optional

Covariance matrix. Exactly one of cov, tau, or chol is needed.

tautensor_like of float, optional

Precision matrix. Exactly one of cov, tau, or chol is needed.

choltensor_like of float, optional

Cholesky decomposition of covariance matrix. Exactly one of cov, tau, or chol is needed.

lower: bool, default=True

Whether chol is the lower tridiagonal cholesky factor.

Examples

Define a multivariate normal variable for a given covariance matrix:

cov = np.array([[1., 0.5], [0.5, 2]])
mu = np.zeros(2)
vals = pm.MvNormal('vals', mu=mu, cov=cov, shape=(5, 2))


Most of the time it is preferable to specify the cholesky factor of the covariance instead. For example, we could fit a multivariate outcome like this (see the docstring of LKJCholeskyCov for more information about this):

mu = np.zeros(3)
true_cov = np.array([[1.0, 0.5, 0.1],
[0.5, 2.0, 0.2],
[0.1, 0.2, 1.0]])
data = np.random.multivariate_normal(mu, true_cov, 10)

sd_dist = pm.Exponential.dist(1.0, shape=3)
chol, corr, stds = pm.LKJCholeskyCov('chol_cov', n=3, eta=2,
sd_dist=sd_dist, compute_corr=True)
vals = pm.MvNormal('vals', mu=mu, chol=chol, observed=data)


For unobserved values it can be better to use a non-centered parametrization:

sd_dist = pm.Exponential.dist(1.0, shape=3)
chol, _, _ = pm.LKJCholeskyCov('chol_cov', n=3, eta=2,
sd_dist=sd_dist, compute_corr=True)
vals_raw = pm.Normal('vals_raw', mu=0, sigma=1, shape=(5, 3))
vals = pm.Deterministic('vals', pt.dot(chol, vals_raw.T).T)


Methods

 MvNormal.dist(mu[, cov, tau, chol, lower]) Creates a tensor variable corresponding to the cls distribution.