Multivariate Analysis in Bayesian Parameter Estimation

Overview

In the context of Bayesian parameter estimation for a Gaussian distribution, the multivariate case extends the univariate analysis to multiple dimensions. This involves modeling the data distribution with a precision matrix and deriving the posterior distribution using Bayes' theorem. The Maximum A Posteriori (MAP) estimate for the mean parameter is particularly noteworthy, as it demonstrates different behaviors depending on the volume of data available.

Multivariate Normal Distribution

A multivariate normal distribution is a generalization of the one-dimensional (univariate) normal distribution to higher dimensions. It is characterized by a mean vector and a covariance matrix. The probability density function (PDF) for a multivariate normal distribution describes the likelihood of a random vector lying within an infinitesimally small volume around a point in the space.

Probability Density Function

The PDF for a multivariate normal distribution can be visualized as a bell-shaped surface in three dimensions, as shown in Figure 5.8. The shape of the base of this bell is controlled by the covariance matrix Σ. In the bivariate case, the distribution is highest at the center and decreases as we move away, approaching zero asymptotically.

Figure 5.8 Bivariate Gaussian random probability density function. It is a bell-shaped surface: highest at the center and decreasing as we move away from the center, approaching zero asymptotically. x = 0,  = 0 has the highest probability, corresponding to the center of the probability density function. The bell has a circular base, and the Σ matrix is a scalar multiple of the identity matrix 𝕀. An interactive visualization (where you can change the parameters and observe how the graph changes as a result) can be found at http://mng.bz/NYJX. Figure 5.8 Bivariate Gaussian random probability density function. It is a bell-shaped surface: highest at the center and decreasing as we move away from the center, approaching zero asymptotically. x = 0, = 0 has the highest probability, corresponding to the center of the probability density function. The bell has a circular base, and the Σ matrix is a scalar multiple of the identity matrix 𝕀. An interactive visualization (where you can change the parameters and observe how the graph changes as a result) can be found at http://mng.bz/NYJX.

Log Probability Calculation

The log probability of a multivariate normal distribution can be computed using PyTorch, as demonstrated in Listing 5.4. This involves setting the distribution parameters, instantiating a multivariate normal distribution object, and evaluating the probability at a given point.

from torch.distributions import MultivariateNormal #1

mu = torch.tensor([0.0, 0.0], dtype=torch.float)   #2
C = torch.tensor([[5.0, 0.0], [0.0, 5.0]], dtype=torch.float)

mvn_dist = MultivariateNormal(mu, C)               #3

X = torch.tensor([0.0, 0.0], dtype=torch.float)    #4

def raw_eval(X, mu, C):
    K = (1 / (2 * math.pi * math.sqrt(C.det())))
    X_minus_mu = (X - mu).reshape(-1, 1)
    E1 = torch.matmul(X_minus_mu.T, C.inverse())
    E = math.exp(-1 / 2. * torch.matmul(E1, X_minus_mu))
    return math.log(K * E)

log_prob = mvn_dist.log_prob(X)                    #5
raw_eval_log_prob = raw_eval(X, mu, C)             #6
assert log_prob == raw_eval_log_prob               #7

Mean and Variance

The mean and variance of a multivariate normal distribution can be estimated by sampling, as shown in Listing 5.6. This involves generating a large number of samples from the distribution and calculating the sample mean and variance, which should closely match the theoretical mean and variance provided by the distribution's parameters.

num_samples = 100000                              #1

samples  = mvn_dist.sample([num_samples])         #3

sample_mean = samples.mean()                      #4
dist_mean = mvn_dist.mean                         #5
assert torch.allclose(sample_mean, dist_mean, atol=1e-1)

sample_var = mvn_dist.sample([num_samples]).var() #6
dist_var = mvn_dist.variance                      #7
assert torch.allclose(sample_var, dist_var, atol=1e-1)

Geometric Properties

The geometric properties of the Gaussian covariance matrix Σ are significant in understanding the distribution's shape. In two dimensions, the PDF can be rewritten to highlight its quadratic form, which defines a hyper-ellipse. This is a generalization of an ellipse to higher dimensions, and all properties of quadratic forms and hyper-ellipses apply to this context.