MultivariateNormalDiag

class paddle.fluid.layers.MultivariateNormalDiag(loc, scale)[source]

A multivariate normal (also called Gaussian) distribution parameterized by a mean vector and a covariance matrix.

Parameters
  • loc (list|numpy.ndarray|Variable) – The mean of multivariateNormal distribution.

  • scale (list|numpy.ndarray|Variable) – The positive definite diagonal covariance matrix of

  • distribution. (multivariateNormal) –

Examples

import numpy as np
from paddle.fluid import layers
from paddle.fluid.layers import MultivariateNormalDiag

a_loc_npdata = np.array([0.3,0.5],dtype="float32")
a_loc_tensor = layers.create_tensor(dtype="float32")
layers.assign(a_loc_npdata, a_loc_tensor)


a_scale_npdata = np.array([[0.4,0],[0,0.5]],dtype="float32")
a_scale_tensor = layers.create_tensor(dtype="float32")
layers.assign(a_scale_npdata, a_scale_tensor)

b_loc_npdata = np.array([0.2,0.4],dtype="float32")
b_loc_tensor = layers.create_tensor(dtype="float32")
layers.assign(b_loc_npdata, b_loc_tensor)

b_scale_npdata = np.array([[0.3,0],[0,0.4]],dtype="float32")
b_scale_tensor = layers.create_tensor(dtype="float32")
layers.assign(b_scale_npdata, b_scale_tensor)

a = MultivariateNormalDiag(a_loc_tensor, a_scale_tensor)
b = MultivariateNormalDiag(b_loc_tensor, b_scale_tensor)

a.entropy()
# [2.033158] with shape: [1]
b.entropy()
# [1.7777451] with shaoe: [1]

a.kl_divergence(b)
# [0.06542051] with shape: [1]
log_prob(value)

Log probability density/mass function.

sample()

Sampling from the distribution.

entropy()

Shannon entropy in nats.

Returns

Shannon entropy of Multivariate Normal distribution.

Return type

Variable

kl_divergence(other)

The KL-divergence between two Multivariate Normal distributions.

Parameters

other (MultivariateNormalDiag) – instance of Multivariate Normal.

Returns

kl-divergence between two Multivariate Normal distributions.

Return type

Variable