Attend the Women in ML Symposium on December 7 Register now

tfp.distributions.CholeskyLKJ

Stay organized with collections Save and categorize content based on your preferences.

The CholeskyLKJ distribution on cholesky factors of correlation matrices.

Inherits From: Distribution, AutoCompositeTensor

This is a one-parameter family of distributions on cholesky factors of correlation matrices.

In other words, if If X ~ CholeskyLKJ(c), then X @ X^T ~ LKJ(c).

The distribution is supported on lower triangular N x N matrices which are Cholesky factors of correlation matrices; equivalently, matrices whose rows have Euclidean norm 1 and diagonal entries are positive. The probability density function is given by:

pdf(X; c) = (1/Z(c)) prod_i X_ii^{n-i+2c-3} (0 <= i < n)

where there are n(n-1)/2 independent variables X_ij (0 <= i < j < n) and Z(c) is the normalizing constant; the same one as that of LKJ(c).

For more details on the LKJ distribution, see tfp.distributions.LKJ.

Examples

# Initialize a single 3x3 LKJ with concentration parameter 1.5
dist = tfp.distributions.CholeskyLKJ(dimension=3, concentration=1.5)

# Evaluate this at a batch of two observations, each in R^{3x3}.
x = ...  # Shape is [2, 3, 3].
dist.prob(x)  # Shape is [2].

# Draw 6 Cholesky LKJ-distributed 3x3 lower triangular matrices
ans = dist.sample(sample_shape=[2, 3], seed=42)
# shape of ans is [2, 3, 3, 3]

The sampler follows the 'onion' method from

[1] Daniel Lewandowski, Dorota Kurowicka, and Harry Joe, 'Generating random correlation matrices based on vines and extended onion method,' Journal of Multivariate Analysis 100 (2009), pp 1989-2001.

dimension Python int. The dimension of the correlation matrices to sample.
concentration float or double Tensor. The positive concentration parameter of the CholeskyLKJ distributions.
validate_args Python bool, default False. When True, distribution parameters are checked for validity despite possibly degrading runtime performance. When False, invalid inputs may silently render incorrect outputs.
allow_nan_stats Python bool, default True. When True, statistics (e.g., mean, mode, variance) use the value NaN to indicate the result is undefined. When False, an exception is raised if one or more of the statistic's batch members are undefined.
name Python str name prefixed to Ops created by this class.

ValueError If dimension is negative.

allow_nan_stats Python bool describing behavior when a stat is undefined.

Stats return +/- infinity when it makes sense. E.g., the variance of a Cauchy distribution is infinity. However, sometimes the statistic is undefined, e.g., if a distribution's pdf does not achieve a maximum within the support of the distribution, the mode is undefined. If the mean is undefined, then by definition the variance is undefined. E.g. the mean for Student's T for df = 1 is undefined (no clear way to say it is either + or - infinity), so the variance = E[(X - mean)**2] is also undefined.

batch_shape Shape of a single sample from a single event index as a TensorShape.

May be partially defined or unknown.

The batch dimensions are indexes into independent, non-identical parameterizations of this distribution.

concentration Concentration parameter.
dimension Dimension of returned cholesky factors of correlation matrices.
dtype The DType of Tensors handled by this Distribution.
event_shape Shape of a single sample from a single batch as a TensorShape.

May be partially defined or unknown.

experimental_shard_axis_names The list or structure of lists of active shard axis names.
name Name prepended to all ops created by this Distribution.
name_scope Returns a tf.name_scope instance for this class.
non_trainable_variables Sequence of non-trainable variables owned by this module and its submodules.

parameters Dictionary of parameters used to instantiate this Distribution.
reparameterization_type Describes how samples from the distribution are reparameterized.

Currently this is one of the static instances tfd.FULLY_REPARAMETERIZED or tfd.NOT_REPARAMETERIZED.

submodules Sequence of all sub-modules.

Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).

a = tf.Module()
b = tf.Module()
c = tf.Module()
a.b = b
b.c = c
list(a.submodules) == [b, c]
True
list(b.submodules) == [c]
True
list(c.submodules) == []
True

trainable_variables Sequence of trainable variables owned by this module and its submodules.

validate_args Python bool indicating possibly expensive checks are enabled.
variables Sequence of variables owned by this module and its submodules.

Methods

batch_shape_tensor

View source

Shape of a single sample from a single event index as a 1-D Tensor.

The batch dimensions are indexes into independent, non-identical parameterizations of this distribution.

Args
name name to give to the op

Returns
batch_shape Tensor.

cdf

View source

Cumulative distribution function.

Given random variable X, the cumulative distribution function cdf is:

cdf(x) := P[X <= x]

Args
value float or double Tensor.
name Python str prepended to names of ops created by this function.
**kwargs Named arguments forwarded to subclass implementation.

Returns
cdf a Tensor of shape sample_shape(x) + self.batch_shape with values of type self.dtype.

copy

View source

Creates a deep copy of the distribution.

Args
**override_parameters_kwargs String/value dictionary of initialization arguments to override with new values.

Returns
distribution A new instance of type(self) initialized from the union of self.parameters and override_parameters_kwargs, i.e., dict(self.parameters, **override_parameters_kwargs).

covariance

View source

Covariance.

Covariance is (possibly) defined only for non-scalar-event distributions.

For example, for a length-k, vector-valued distribution, it is calculated as,

Cov[i, j] = Covariance(X_i, X_j) = E[(X_i - E[X_i]) (X_j - E[X_j])]

where Cov is a (batch of) k x k matrix, 0 <= (i, j) < k, and E denotes expectation.

Alternatively, for non-vector, multivariate distributions (e.g., matrix-valued, Wishart), Covariance shall return a (batch of) matrices under some vectorization of the events, i.e.,

Cov[i, j] = Covariance(Vec(X)_i, Vec(X)_j) = [as above]

where Cov is a (batch of) k' x k' matrices, 0 <= (i, j) < k' = reduce_prod(event_shape), and Vec is some function mapping indices of this distribution's event dimensions to indices of a length-k' vector.

Args
name Python str prepended to names of ops created by this function.
**kwargs Named arguments forwarded to subclass implementation.

Returns
covariance Floating-point Tensor with shape [B1, ..., Bn, k', k'] where the first n dimensions are batch coordinates and k' = reduce_prod(self.event_shape).

cross_entropy

View source

Computes the (Shannon) cross entropy.

Denote this distribution (self) by P and the other distribution by Q. Assuming P, Q are absolutely continuous with respect to one another and permit densities p(x) dr(x) and q(x) dr(x), (Shannon) cross entropy is defined as:

H[P, Q] = E_p[-log q(X)] = -int_F p(x) log q(x) dr(x)

where F denotes the support of the random variable X ~ P.

Args
other tfp.distributions.Distribution instance.
name Pyth