prfmodel.density.normal_density

prfmodel.density.normal_density(value: prfmodel.typing.Tensor, mu: prfmodel.typing.Tensor, sigma: prfmodel.typing.Tensor) → prfmodel.typing.Tensor

Calculate the density of an isotropic multivariate normal distribution.

The multivariate normal distribution has a diagonal covariance matrix with \(\mathtt{sigma}^2\) on the diagonal (i.e., all dimensions have the same standard deviation sigma).

Parameters:
  • value (prfmodel.typing.Tensor) – Values at which to evaluate the normal distribution. The last axis indexes the dimensions of the distribution.

  • mu (prfmodel.typing.Tensor) – Mean of the normal distribution. Must be broadcastable to the shape of value.

  • sigma (prfmodel.typing.Tensor) – Standard deviation of the normal distribution. Because the distribution is isotropic, sigma does not have a dimension axis and must be broadcastable to the shape of value without its last axis.

Returns:

The normal density at value with the shape of value without its last axis.

Return type:

prfmodel.typing.Tensor

Notes

The density of the isotropic multivariate normal distribution with mean \(\mu\) and standard deviation \(\sigma\) in \(k\) dimensions is given by:

\[f(x) = \frac{1}{(2 \pi \sigma^2)^{k / 2}} e^{-\frac{\lVert x - \mu \rVert^2}{2 \sigma^2}}.\]

Examples

>>> import numpy as np
>>> from prfmodel.density import normal_density
>>> value = np.zeros((4, 3, 2))   # 4 x 3 points in 2 dimensions
>>> mu = np.array([0.0, 1.0])   # shape (2,)
>>> sigma = np.array([[1.0]])   # shape (1, 1)
>>> dens = normal_density(value, mu, sigma)
>>> print(dens.shape)
(4, 3)