Gaussian#

class cuqi.distribution.Gaussian(mean=None, cov=None, prec=None, sqrtcov=None, sqrtprec=None, is_symmetric=True, **kwargs)#

General Gaussian probability distribution. Generates instance of cuqi.distribution.Gaussian.

The Gaussian is defined via the probability density function

\[p(x) = \frac{1}{(2\pi)^{\frac{d}{2}}|\Sigma|^{\frac{1}{2}}} \exp\left(-\frac{1}{2}(x-\mu)^{\top}\Sigma^{-1}(x-\mu)\right)\]

where \(\mu\) is the mean, \(\Sigma\) is the covariance matrix, and \(d\) is the dimension of the Gaussian.

Depending on the specific Gaussian distribution, it is useful to have the option of defining the Gaussian by a mean and one of the following: covariance, precision, square root of covariance, or square root of precision matrices. The relationship between these matrices is described in the parameters section below.

Internally the class will always convert the given matrices to the square root of the precision matrix for efficiency. It is therefore best for computational efficiency to define the Gaussian via the square root of the precision matrix in the multivariate case. For the i.i.d. case the overhead of computing the square root of the precision matrix is negligible.

Parameters:
  • mean (scalar or 1d-array) – Mean vector of Gaussian. If a scalar value, all entries in the mean vector are set to that scalar.

  • cov (scalar, 1d-array or 2d-array (sparse matrix is supported)) – Covariance matrix of Gaussian. If a scalar or 1d-array, the value defines the diagonal entries of the covariance matrix.

  • prec (scalar, 1d-array or 2d-array (sparse matrix is supported)) – Precision matrix of Gaussian defined as the inverse of the covariance. If a scalar or 1d-array, the value defines the diagonal entries of the precision matrix.

  • sqrtcov (scalar, 1d-array or 2d-array (sparse matrix is supported)) – Square root of covariance matrix of Gaussian. Defined as matrix R, where R.T@R = cov. If a scalar or 1d-array the value is assumed to be the standard deviation of each component of the Gaussian.

  • sqrtprec (scalar or 1d-array or 2d-array (sparse matrix is supported)) – Square root of precision matrix of Gaussian. Defined as matrix R, where R.T@R = prec. If a scalar or 1d-array the value is assumed to be the inverse standard deviation of each component of the Gaussian.

Example

# Generate an i.i.d. n-dim Gaussian with zero mean and 2 variance.
n = 4
x = cuqi.distribution.Gaussian(mean=np.zeros(n), cov=2)
# Generate an 2-dim Gaussian with zero mean and standard deviations [2, 10].
x = cuqi.distribution.Gaussian(mean=0, sqrtcov=np.array([2, 10]))
# Generate an n-dim Gaussian from given scipy.sparse precision matrix.
n = 5
prec = scipy.sparse.diags([-1, 2, -1], [-1, 0, 1], shape=(n, n))
x = cuqi.distribution.Gaussian(mean=0, prec=prec)
# Generate an n-dim Gaussian from given scipy.sparse square root of precision matrix.
n = 5
sqrtprec = scipy.sparse.diags([1, -1], [0, 1], shape=(n, n))
x = cuqi.distribution.Gaussian(mean=0, sqrtprec=sqrtprec)
__init__(mean=None, cov=None, prec=None, sqrtcov=None, sqrtprec=None, is_symmetric=True, **kwargs)#

Initialize the core properties of the distribution.

Parameters:
  • name (str, default None) – Name of distribution.

  • geometry (Geometry, default _DefaultGeometry (or None)) – Geometry of distribution.

  • is_symmetric (bool, default None) – Indicator if distribution is symmetric.

Methods

__init__([mean, cov, prec, sqrtcov, ...])

Initialize the core properties of the distribution.

cdf(x1)

compute_cov()

Computes the covariance matrix regardless of the mutable variables.

disable_FD()

Disable finite difference approximation for logd gradient.

enable_FD([epsilon])

Enable finite difference approximation for logd gradient.

get_conditioning_variables()

Return the conditioning variables of this distribution (if any).

get_mutable_variables()

Return any public variable that is mutable (attribute or property) except those in the ignore_vars list

get_parameter_names()

Returns the names of the parameters that the density can be evaluated at or conditioned on.

gradient(*args, **kwargs)

Returns the gradient of the log density at x.

logd(*args, **kwargs)

Evaluate the un-normalized log density function of the distribution.

logpdf(x)

Evaluate the log probability density function of the distribution.

pdf(x)

Evaluate the log probability density function of the distribution.

sample([N])

Sample from the distribution.

to_likelihood(data)

Convert conditional distribution to a likelihood function given observed data

Attributes

FD_enabled

Returns True if finite difference approximation of the logd gradient is enabled.

FD_epsilon

Spacing for the finite difference approximation of the logd gradient.

cov

Covariance of the distribution

dim

Return the dimension of the distribution based on the geometry.

geometry

Return the geometry of the distribution.

is_cond

Returns True if instance (self) is a conditional distribution.

logdet

Logarithm of the determinant of the covariance of the distribution

mean

Mean of the distribution

name

Name of the random variable associated with the density.

prec

Precision of the distribution

rank

sqrtcov

Square root of the covariance of the distribution.

sqrtprec

Square root of the precision of the distribution.

sqrtprecTimesMean