[TOC]
Classes representing statistical distributions and ops for working with them.
Classes that represent batches of statistical distributions. Each class is initialized with parameters that define the distributions.
Abstract base class for probability distributions.
This class, along with ContinuousDistribution and DiscreteDistribution,
defines the API for probability distributions.
Users will never instantiate a BaseDistribution, but will instead
instantiate subclasses of either ContinuousDistribution or
DiscreteDistribution.
Developers of new distributions should prefer to subclass
ContinuousDistribution or DiscreteDistribution.
The key methods for probability distributions are defined here. The likelihood
functions (pdf, log_pdf) and (pmf, log_pmf) are defined in
ContinuousDistribution and DiscreteDistribution, respectively.
To keep ops generated by the distribution tied together by name, subclasses
should override name and use it to preprend names of ops in other methods
(see cdf for an example).
Subclasses that wish to support cdf and log_cdf can override log_cdf
and use the base class's implementation for cdf.
All distributions support batches of independent distributions of that type. The batch shape is determined by broadcasting together the parameters.
The shape of arguments to __init__, cdf, log_cdf, and the likelihood
functions defined in ContinuousDistribution and DiscreteDistribution
reflect this broadcasting, as does the return value of sample.
sample_shape = (n,) + batch_shape + event_shape, where sample_shape is the
shape of the Tensor returned from sample, n is the number of samples,
batch_shape defines how many independent distributions there are, and
event_shape defines the shape of samples from each of those independent
distributions. Samples are independent along the batch_shape dimensions,
but not necessarily so along the event_shape dimensions (dependending on
the particulars of the underlying distribution).
Using the Uniform distribution as an example:
minval = 3.0
maxval = [[4.0, 6.0],
[10.0, 12.0]]
# Broadcasting:
# This instance represents 4 Uniform distributions. Each has a lower bound at
# 3.0 as the `minval` parameter was broadcasted to match `maxval`'s shape.
u = Uniform(minval, maxval)
# `event_shape` is `TensorShape([])`.
event_shape = u.get_event_shape()
# `event_shape_t` is a `Tensor` which will evaluate to a scalar 1.
event_shape_t = u.event_shape
# Sampling returns a sample per distribution. `samples` has shape
# (5, 2, 2), which is (n,) + batch_shape + event_shape, where n=5,
# batch_shape=(2, 2), and event_shape=().
samples = u.sample(5)
# The broadcasting holds across methods. Here we use `cdf` as an example. The
# same holds for `log_cdf` and the likelihood functions.
# `cum_prob` has shape (2, 2) as the `value` argument was broadcasted to the
# shape of the `Uniform` instance.
cum_prob_broadcast = u.cdf(4.0)
# `cum_prob`'s shape is (2, 2), one per distribution. No broadcasting
# occurred.
cum_prob_per_dist = u.cdf([[4.0, 5.0],
[6.0, 7.0]])
# INVALID as the `value` argument is not broadcastable to the distribution's
# shape.
cum_prob_invalid = u.cdf([4.0, 5.0, 6.0])Batch dimensions of this instance as a 1-D int32 Tensor.
The product of the dimensions of the batch_shape is the number of
independent distributions of this kind the instance represents.
name: name to give to the op
Tensor batch_shape
Cumulative distribution function.
dtype of samples from this distribution.
Entropy of the distribution in nats.
Shape of a sample from a single distribution as a 1-D int32 Tensor.
name: name to give to the op
Tensor event_shape
TensorShape available at graph construction time.
Same meaning as batch_shape. May be only partially defined.
TensorShape available at graph construction time.
Same meaning as event_shape. May be only partially defined.
tf.contrib.distributions.BaseDistribution.log_cdf(value, name='log_cdf') {#BaseDistribution.log_cdf}
Log CDF.
Name to prepend to all ops.
tf.contrib.distributions.BaseDistribution.sample(n, seed=None, name=None) {#BaseDistribution.sample}
Generate n samples.
n: scalar. Number of samples to draw from each distribution.seed: Python integer seed for RNGname: name to give to the op.
samples: aTensorof shape(n,) + self.batch_shape + self.event_shapewith values of typeself.dtype.
Base class for continuous probability distributions.
ContinuousDistribution defines the API for the likelihood functions pdf
and log_pdf of continuous probability distributions, and a property
is_reparameterized (returning True or False) which describes
whether the samples of this distribution are calculated in a differentiable
way from a non-parameterized distribution. For example, the Normal
distribution with parameters mu and sigma is reparameterized as
Normal(mu, sigma) = sigma * Normal(0, 1) + mu
Subclasses must override pdf and log_pdf but one can call this base
class's implementation. They must also override the is_reparameterized
property.
See BaseDistribution for more information on the API for probability
distributions.
tf.contrib.distributions.ContinuousDistribution.batch_shape(name=None) {#ContinuousDistribution.batch_shape}
Batch dimensions of this instance as a 1-D int32 Tensor.
The product of the dimensions of the batch_shape is the number of
independent distributions of this kind the instance represents.
name: name to give to the op
Tensor batch_shape
tf.contrib.distributions.ContinuousDistribution.cdf(value, name='cdf') {#ContinuousDistribution.cdf}
Cumulative distribution function.
dtype of samples from this distribution.
tf.contrib.distributions.ContinuousDistribution.entropy(name=None) {#ContinuousDistribution.entropy}
Entropy of the distribution in nats.
tf.contrib.distributions.ContinuousDistribution.event_shape(name=None) {#ContinuousDistribution.event_shape}
Shape of a sample from a single distribution as a 1-D int32 Tensor.
name: name to give to the op
Tensor event_shape
tf.contrib.distributions.ContinuousDistribution.get_batch_shape() {#ContinuousDistribution.get_batch_shape}
TensorShape available at graph construction time.
Same meaning as batch_shape. May be only partially defined.
tf.contrib.distributions.ContinuousDistribution.get_event_shape() {#ContinuousDistribution.get_event_shape}
TensorShape available at graph construction time.
Same meaning as event_shape. May be only partially defined.
tf.contrib.distributions.ContinuousDistribution.is_reparameterized {#ContinuousDistribution.is_reparameterized}
tf.contrib.distributions.ContinuousDistribution.log_cdf(value, name='log_cdf') {#ContinuousDistribution.log_cdf}
Log CDF.
tf.contrib.distributions.ContinuousDistribution.log_pdf(value, name='log_pdf') {#ContinuousDistribution.log_pdf}
Log of the probability density function.
Name to prepend to all ops.
tf.contrib.distributions.ContinuousDistribution.pdf(value, name='pdf') {#ContinuousDistribution.pdf}
Probability density function.
tf.contrib.distributions.ContinuousDistribution.sample(n, seed=None, name=None) {#ContinuousDistribution.sample}
Generate n samples.
n: scalar. Number of samples to draw from each distribution.seed: Python integer seed for RNGname: name to give to the op.
samples: aTensorof shape(n,) + self.batch_shape + self.event_shapewith values of typeself.dtype.
Base class for discrete probability distributions.
DiscreteDistribution defines the API for the likelihood functions pmf and
log_pmf of discrete probability distributions.
Subclasses must override both pmf and log_pmf but one can call this base
class's implementation.
See BaseDistribution for more information on the API for probability
distributions.
tf.contrib.distributions.DiscreteDistribution.batch_shape(name=None) {#DiscreteDistribution.batch_shape}
Batch dimensions of this instance as a 1-D int32 Tensor.
The product of the dimensions of the batch_shape is the number of
independent distributions of this kind the instance represents.
name: name to give to the op
Tensor batch_shape
Cumulative distribution function.
dtype of samples from this distribution.
Entropy of the distribution in nats.
tf.contrib.distributions.DiscreteDistribution.event_shape(name=None) {#DiscreteDistribution.event_shape}
Shape of a sample from a single distribution as a 1-D int32 Tensor.
name: name to give to the op
Tensor event_shape
tf.contrib.distributions.DiscreteDistribution.get_batch_shape() {#DiscreteDistribution.get_batch_shape}
TensorShape available at graph construction time.
Same meaning as batch_shape. May be only partially defined.
tf.contrib.distributions.DiscreteDistribution.get_event_shape() {#DiscreteDistribution.get_event_shape}
TensorShape available at graph construction time.
Same meaning as event_shape. May be only partially defined.
tf.contrib.distributions.DiscreteDistribution.log_cdf(value, name='log_cdf') {#DiscreteDistribution.log_cdf}
Log CDF.
tf.contrib.distributions.DiscreteDistribution.log_pmf(value, name='log_pmf') {#DiscreteDistribution.log_pmf}
Log of the probability mass function.
Name to prepend to all ops.
Probability mass function.
tf.contrib.distributions.DiscreteDistribution.sample(n, seed=None, name=None) {#DiscreteDistribution.sample}
Generate n samples.
n: scalar. Number of samples to draw from each distribution.seed: Python integer seed for RNGname: name to give to the op.
samples: aTensorof shape(n,) + self.batch_shape + self.event_shapewith values of typeself.dtype.
The Chi2 distribution with degrees of freedom df.
The PDF of this distribution is:
pdf(x) = (x^(df/2 - 1)e^(-x/2))/(2^(k/2)Gamma(k/2)), x > 0
Note that the Chi2 distribution is a special case of the Gamma distribution, with Chi2(df) = Gamma(df/2, 1/2).
Shape parameter.
Batch dimensions of this instance as a 1-D int32 Tensor.
The product of the dimensions of the batch_shape is the number of
independent distributions of this kind the instance represents.
name: name to give to the op
Tensor batch_shape
Inverse scale parameter.
CDF of observations x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
cdf: tensor of dtypedtype, the CDFs ofx.
dtype of samples from this distribution.
The entropy of Gamma distribution(s).
This is defined to be
entropy = alpha - log(beta) + log(Gamma(alpha))
+ (1-alpha)digamma(alpha)
where digamma(alpha) is the digamma function.
name: The name to give this op.
entropy: tensor of dtypedtype, the entropy.
Shape of a sample from a single distribution as a 1-D int32 Tensor.
name: name to give to the op
Tensor event_shape
TensorShape available at graph construction time.
Same meaning as batch_shape. May be only partially defined.
TensorShape object.
TensorShape available at graph construction time.
Same meaning as event_shape. May be only partially defined.
TensorShape object.
Log CDF of observations x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
log_cdf: tensor of dtypedtype, the log-CDFs ofx.
Log pdf of observations in x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
log_pdf: tensor of dtypedtype, the log-PDFs ofx.
TypeError: ifxandalphaare different dtypes.
Mean of each batch member.
Name to prepend to all ops.
Pdf of observations in x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
pdf: tensor of dtypedtype, the PDFs ofx
TypeError: ifxandalphaare different dtypes.
Generate n samples.
n: scalar. Number of samples to draw from each distribution.seed: Python integer seed for RNGname: name to give to the op.
samples: aTensorof shape(n,) + self.batch_shape + self.event_shapewith values of typeself.dtype.
Variance of each batch member.
The Exponential distribution with rate parameter lam.
The PDF of this distribution is:
pdf(x) = (lam * e^(-lam * x)), x > 0
Note that the Exponential distribution is a special case of the Gamma distribution, with Exponential(lam) = Gamma(1, lam).
Shape parameter.
Batch dimensions of this instance as a 1-D int32 Tensor.
The product of the dimensions of the batch_shape is the number of
independent distributions of this kind the instance represents.
name: name to give to the op
Tensor batch_shape
Inverse scale parameter.
CDF of observations x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
cdf: tensor of dtypedtype, the CDFs ofx.
dtype of samples from this distribution.
The entropy of Gamma distribution(s).
This is defined to be
entropy = alpha - log(beta) + log(Gamma(alpha))
+ (1-alpha)digamma(alpha)
where digamma(alpha) is the digamma function.
name: The name to give this op.
entropy: tensor of dtypedtype, the entropy.
Shape of a sample from a single distribution as a 1-D int32 Tensor.
name: name to give to the op
Tensor event_shape
TensorShape available at graph construction time.
Same meaning as batch_shape. May be only partially defined.
TensorShape object.
TensorShape available at graph construction time.
Same meaning as event_shape. May be only partially defined.
TensorShape object.
Log CDF of observations x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
log_cdf: tensor of dtypedtype, the log-CDFs ofx.
Log pdf of observations in x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
log_pdf: tensor of dtypedtype, the log-PDFs ofx.
TypeError: ifxandalphaare different dtypes.
Mean of each batch member.
Name to prepend to all ops.
Pdf of observations in x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
pdf: tensor of dtypedtype, the PDFs ofx
TypeError: ifxandalphaare different dtypes.
Sample n observations from the Exponential Distributions.
n:Scalar, type int32, the number of observations to sample.seed: Python integer, the random seed.name: The name to give this op.
samples:[n, ...], aTensorofnsamples for each of the distributions determined by the hyperparameters.
Variance of each batch member.
The Gamma distribution with parameter alpha and beta.
The parameters are the shape and inverse scale parameters alpha, beta.
The PDF of this distribution is:
pdf(x) = (beta^alpha)(x^(alpha-1))e^(-x*beta)/Gamma(alpha), x > 0
and the CDF of this distribution is:
cdf(x) = GammaInc(alpha, beta * x) / Gamma(alpha), x > 0
where GammaInc is the incomplete lower Gamma function.
Examples:
dist = Gamma(alpha=3.0, beta=2.0)
dist2 = Gamma(alpha=[3.0, 4.0], beta=[2.0, 3.0])Construct Gamma distributions with parameters alpha and beta.
The parameters alpha and beta must be shaped in a way that supports
broadcasting (e.g. alpha + beta is a valid operation).
alpha:floatordoubletensor, the shape params of the distribution(s). alpha must contain only positive values.beta:floatordoubletensor, the inverse scale params of the distribution(s). beta must contain only positive values.name: The name to prepend to all ops created by this distribution.
TypeError: ifalphaandbetaare different dtypes.
Shape parameter.
Batch dimensions of this instance as a 1-D int32 Tensor.
The product of the dimensions of the batch_shape is the number of
independent distributions of this kind the instance represents.
name: name to give to the op
Tensor batch_shape
Inverse scale parameter.
CDF of observations x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
cdf: tensor of dtypedtype, the CDFs ofx.
dtype of samples from this distribution.
The entropy of Gamma distribution(s).
This is defined to be
entropy = alpha - log(beta) + log(Gamma(alpha))
+ (1-alpha)digamma(alpha)
where digamma(alpha) is the digamma function.
name: The name to give this op.
entropy: tensor of dtypedtype, the entropy.
Shape of a sample from a single distribution as a 1-D int32 Tensor.
name: name to give to the op
Tensor event_shape
TensorShape available at graph construction time.
Same meaning as batch_shape. May be only partially defined.
TensorShape object.
TensorShape available at graph construction time.
Same meaning as event_shape. May be only partially defined.
TensorShape object.
Log CDF of observations x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
log_cdf: tensor of dtypedtype, the log-CDFs ofx.
Log pdf of observations in x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
log_pdf: tensor of dtypedtype, the log-PDFs ofx.
TypeError: ifxandalphaare different dtypes.
Mean of each batch member.
Name to prepend to all ops.
Pdf of observations in x under these Gamma distribution(s).
x: tensor of dtypedtype, must be broadcastable withalphaandbeta.name: The name to give this op.
pdf: tensor of dtypedtype, the PDFs ofx
TypeError: ifxandalphaare different dtypes.
Generate n samples.
n: scalar. Number of samples to draw from each distribution.seed: Python integer seed for RNGname: name to give to the op.
samples: aTensorof shape(n,) + self.batch_shape + self.event_shapewith values of typeself.dtype.
Variance of each batch member.
The scalar Normal distribution with mean and stddev parameters mu, sigma.
The PDF of this distribution is:
f(x) = sqrt(1/(2*pi*sigma^2)) exp(-(x-mu)^2/(2*sigma^2))
Examples of initialization of one or a batch of distributions.
# Define a single scalar Normal distribution.
dist = tf.contrib.distributions.Normal(mu=0, sigma=3)
# Evaluate the cdf at 1, returning a scalar.
dist.cdf(1)
# Define a batch of two scalar valued Normals.
# The first has mean 1 and standard deviation 11, the second 2 and 22.
dist = tf.contrib.distributions.Normal(mu=[1, 2.], sigma=[11, 22.])
# Evaluate the pdf of the first distribution on 0, and the second on 1.5,
# returning a length two tensor.
dist.pdf([0, 1.5])
# Get 3 samples, returning a 3 x 2 tensor.
dist.sample(3)Arguments are broadcast when possible.
# Define a batch of two scalar valued Normals.
# Both have mean 1, but different standard deviations.
dist = tf.contrib.distributions.Normal(mu=1, sigma=[11, 22.])
# Evaluate the pdf of both distributions on the same point, 3.0,
# returning a length 2 tensor.
dist.pdf(3.0)Construct Normal distributions with mean and stddev mu and sigma.
The parameters mu and sigma must be shaped in a way that supports
broadcasting (e.g. mu + sigma is a valid operation).
mu:floatordoubletensor, the means of the distribution(s).sigma:floatordoubletensor, the stddevs of the distribution(s). sigma must contain only positive values.name: The name to give Ops created by the initializer.
TypeError: if mu and sigma are different dtypes.
CDF of observations in x under these Normal distribution(s).
x: tensor of dtypedtype, must be broadcastable withmuandsigma.name: The name to give this op.
cdf: tensor of dtypedtype, the CDFs ofx.
The entropy of Normal distribution(s).
name: The name to give this op.
entropy: tensor of dtypedtype, the entropy.
Log CDF of observations x under these Normal distribution(s).
x: tensor of dtypedtype, must be broadcastable withmuandsigma.name: The name to give this op.
log_cdf: tensor of dtypedtype, the log-CDFs ofx.
Log pdf of observations in x under these Normal distribution(s).
x: tensor of dtypedtype, must be broadcastable withmuandsigma.name: The name to give this op.
log_pdf: tensor of dtypedtype, the log-PDFs ofx.
The PDF of observations in x under these Normal distribution(s).
x: tensor of dtypedtype, must be broadcastable withmuandsigma.name: The name to give this op.
pdf: tensor of dtypedtype, the pdf values ofx.
Sample n observations from the Normal Distributions.
n:Scalar, type int32, the number of observations to sample.seed: Python integer, the random seed.name: The name to give this op.
samples:[n, ...], aTensorofnsamples for each of the distributions determined by broadcasting the hyperparameters.
Student's t distribution with degree-of-freedom parameter df.
The PDF of this distribution is:
f(t) = gamma((df+1)/2)/sqrt(df*pi)/gamma(df/2)*(1+t^2/df)^(-(df+1)/2)
Examples of initialization of one or a batch of distributions.
# Define a single scalar Student t distribution.
single_dist = tf.contrib.distributions.StudentT(df=3)
# Evaluate the pdf at 1, returning a scalar Tensor.
single_dist.pdf(1.)
# Define a batch of two scalar valued Student t's.
# The first has degrees of freedom 2, mean 1, and scale 11.
# The second 3, 2 and 22.
multi_dist = tf.contrib.distributions.StudentT(df=[2, 3],
mu=[1, 2.],
sigma=[11, 22.])
# Evaluate the pdf of the first distribution on 0, and the second on 1.5,
# returning a length two tensor.
multi_dist.pdf([0, 1.5])
# Get 3 samples, returning a 3 x 2 tensor.
multi_dist.sample(3)Arguments are broadcast when possible.
# Define a batch of two Student's t distributions.
# Both have df 2 and mean 1, but different scales.
dist = tf.contrib.distributions.StudentT(df=2, mu=1, sigma=[11, 22.])
# Evaluate the pdf of both distributions on the same point, 3.0,
# returning a length 2 tensor.
dist.pdf(3.0)Construct Student's t distributions.
The distributions have degree of freedom df, mean mu, and scale sigma.
The parameters df, mu, and sigma must be shaped in a way that supports
broadcasting (e.g. df + mu + sigma is a valid operation).
df:floatordoubletensor, the degrees of freedom of the distribution(s).dfmust contain only positive values.mu:floatordoubletensor, the means of the distribution(s).sigma:floatordoubletensor, the scaling factor for the distribution(s).sigmamust contain only positive values. Note thatsigmais not the standard deviation of this distribution.name: The name to give Ops created by the initializer.
TypeError: if mu and sigma are different dtypes.
Cumulative distribution function.
Degrees of freedom in these Student's t distribution(s).
The entropy of Student t distribution(s).
name: The name to give this op.
entropy: tensor of dtypedtype, the entropy.
Log CDF.
Log pdf of observations in x under these Student's t-distribution(s).
x: tensor of dtypedtype, must be broadcastable withmuanddf.name: The name to give this op.
log_pdf: tensor of dtypedtype, the log-PDFs ofx.
Locations of these Student's t distribution(s).
The PDF of observations in x under these Student's t distribution(s).
x: tensor of dtypedtype, must be broadcastable withdf,mu, andsigma.name: The name to give this op.
pdf: tensor of dtypedtype, the pdf values ofx.
Sample n observations from the Student t Distributions.
n:Scalar, type int32, the number of observations to sample.seed: Python integer, the random seed.name: The name to give this op.
samples: aTensorof shape(n,) + self.batch_shape + self.event_shapewith values of typeself.dtype.
Scaling factors of these Student's t distribution(s).
Uniform distribution with a and b parameters.
The PDF of this distribution is constant between [a, b], and 0 elsewhere.
Construct Uniform distributions with a and b.
The parameters a and b must be shaped in a way that supports
broadcasting (e.g. b - a is a valid operation).
Here are examples without broadcasting:
# Without broadcasting
u1 = Uniform(3.0, 4.0) # a single uniform distribution [3, 4]
u2 = Uniform([1.0, 2.0], [3.0, 4.0]) # 2 distributions [1, 3], [2, 4]
u3 = Uniform([[1.0, 2.0],
[3.0, 4.0]],
[[1.5, 2.5],
[3.5, 4.5]]) # 4 distributionsAnd with broadcasting:
u1 = Uniform(3.0, [5.0, 6.0, 7.0]) # 3 distributionsa:floatordoubletensor, the minimum endpoint.b:floatordoubletensor, the maximum endpoint. Must be >a.name: The name to prefix Ops created by this distribution class.
InvalidArgumentError: ifa >= b.
CDF of observations in x under these Uniform distribution(s).
x: tensor of dtypedtype, must be broadcastable withaandb.name: The name to give this op.
cdf: tensor of dtypedtype, the CDFs ofx. Ifxisnan, will returnnan.
The entropy of Uniform distribution(s).
name: The name to give this op.
entropy: tensor of dtypedtype, the entropy.
The PDF of observations in x under these Uniform distribution(s).
x: tensor of dtypedtype, must be broadcastable withaandb.name: The name to give this op.
pdf: tensor of dtypedtype, the pdf values ofx. Ifxisnan, will returnnan.
b - a.
Sample n observations from the Uniform Distributions.
n:Scalar, type int32, the number of observations to sample.seed: Python integer, the random seed.name: The name to give this op.
samples: aTensorof shape(n,) + self.batch_shape + self.event_shapewith values of typeself.dtype.
The Multivariate Normal distribution on R^k.
The distribution has mean and covariance parameters mu (1-D), sigma (2-D),
or alternatively mean mu and factored covariance (cholesky decomposed
sigma) called sigma_chol.
The PDF of this distribution is:
f(x) = (2*pi)^(-k/2) |det(sigma)|^(-1/2) exp(-1/2*(x-mu)^*.sigma^{-1}.(x-mu))
where . denotes the inner product on R^k and ^* denotes transpose.
Alternatively, if sigma is positive definite, it can be represented in terms
of its lower triangular cholesky factorization
sigma = sigma_chol . sigma_chol^*
and the pdf above allows simpler computation:
|det(sigma)| = reduce_prod(diag(sigma_chol))^2
x_whitened = sigma^{-1/2} . (x - mu) = tri_solve(sigma_chol, x - mu)
(x-mu)^* .sigma^{-1} . (x-mu) = x_whitened^* . x_whitened
where tri_solve() solves a triangular system of equations.
A single multi-variate Gaussian distribution is defined by a vector of means
of length k, and a covariance matrix of shape k x k.
Extra leading dimensions, if provided, allow for batches.
# Initialize a single 3-variate Gaussian with diagonal covariance.
mu = [1, 2, 3]
sigma = [[1, 0, 0], [0, 3, 0], [0, 0, 2]]
dist = tf.contrib.distributions.MultivariateNormal(mu=mu, sigma=sigma)
# Evaluate this on an observation in R^3, returning a scalar.
dist.pdf([-1, 0, 1])
# Initialize a batch of two 3-variate Gaussians.
mu = [[1, 2, 3], [11, 22, 33]]
sigma = ... # shape 2 x 3 x 3
dist = tf.contrib.distributions.MultivariateNormal(mu=mu, sigma=sigma)
# Evaluate this on a two observations, each in R^3, returning a length two
# tensor.
x = [[-1, 0, 1], [-11, 0, 11]] # Shape 2 x 3.
dist.pdf(x)tf.contrib.distributions.MultivariateNormal.__init__(mu, sigma=None, sigma_chol=None, name=None) {#MultivariateNormal.init}
Multivariate Normal distributions on R^k.
User must provide means mu, which are tensors of rank N+1 (N >= 0)
with the last dimension having length k.
User must provide exactly one of sigma (the covariance matrices) or
sigma_chol (the cholesky decompositions of the covariance matrices).
sigma or sigma_chol must be of rank N+2. The last two dimensions
must both have length k. The first N dimensions correspond to batch
indices.
If sigma_chol is not provided, the batch cholesky factorization of sigma
is calculated for you.
The shapes of mu and sigma must match for the first N dimensions.
Regardless of which parameter is provided, the covariance matrices must all be positive definite (an error is raised if one of them is not).
mu: (N+1)-D.floatordoubletensor, the means of the distributions.sigma: (N+2)-D. (optional)floatordoubletensor, the covariances of the distribution(s). The firstN+1dimensions must match those ofmu. Must be batch-positive-definite.sigma_chol: (N+2)-D. (optional)floatordoubletensor, a lower-triangular factorization ofsigma(sigma = sigma_chol . sigma_chol^*). The firstN+1dimensions must match those ofmu. The tensor itself need not be batch lower triangular: we ignore the upper triangular part. However, the batch diagonals must be positive (i.e., sigma_chol must be batch-positive-definite).name: The name to give Ops created by the initializer.
ValueError: if neither sigma nor sigma_chol is provided.TypeError: if mu and sigma (resp. sigma_chol) are different dtypes.
The entropies of these Multivariate Normals.
name: The name to give this op.
entropy: tensor of dtypedtype, the entropies.
tf.contrib.distributions.MultivariateNormal.is_reparameterized {#MultivariateNormal.is_reparameterized}
Log pdf of observations x given these Multivariate Normals.
x: tensor of dtypedtype, must be broadcastable withmu.name: The name to give this op.
log_pdf: tensor of dtypedtype, the log-PDFs ofx.
The PDF of observations x under these Multivariate Normals.
x: tensor of dtypedtype, must be broadcastable withmuandsigma.name: The name to give this op.
pdf: tensor of dtypedtype, the pdf values ofx.
tf.contrib.distributions.MultivariateNormal.sample(n, seed=None, name=None) {#MultivariateNormal.sample}
Sample n observations from the Multivariate Normal Distributions.
n:Scalar, type int32, the number of observations to sample.seed: Python integer, the random seed.name: The name to give this op.
samples:[n, ...], aTensorofnsamples for each of the distributions determined by broadcasting the hyperparameters.
DirichletMultinomial mixture distribution.
This distribution is parameterized by a vector alpha of concentration
parameters for k classes.
The Dirichlet Multinomial is a distribution over k-class count data, meaning
for each k-tuple of non-negative integer counts = [c_1,...,c_k], we have a
probability of these draws being made from the distribution. The distribution
has hyperparameters alpha = (alpha_1,...,alpha_k), and probability mass
function (pmf):
pmf(counts) = C! / (c_1!...c_k!) * Beta(alpha + c) / Beta(alpha)
where above C = sum_j c_j, N! is N factorial, and
Beta(x) = prod_j Gamma(x_j) / Gamma(sum_j x_j) is the multivariate beta
function.
This is a mixture distribution in that N samples can be produced by:
- Choose class probabilities
p = (p_1,...,p_k) ~ Dir(alpha) - Draw integers
m = (m_1,...,m_k) ~ Multinomial(p, N)
This class provides methods to create indexed batches of Dirichlet
Multinomial distributions. If the provided alpha is rank 2 or higher, for
every fixed set of leading dimensions, the last dimension represents one
single Dirichlet Multinomial distribution. When calling distribution
functions (e.g. dist.pdf(counts)), alpha and counts are broadcast to the
same shape (if possible). In all cases, the last dimension of alpha/counts
represents single Dirichlet Multinomial distributions.
alpha = [1, 2, 3]
dist = DirichletMultinomial(alpha)Creates a 3-class distribution, with the 3rd class is most likely to be drawn. The distribution functions can be evaluated on counts.
# counts same shape as alpha.
counts = [0, 2, 0]
dist.pdf(counts) # Shape []
# alpha will be broadcast to [[1, 2, 3], [1, 2, 3]] to match counts.
counts = [[11, 22, 33], [44, 55, 66]]
dist.pdf(counts) # Shape [2]
# alpha will be broadcast to shape [5, 7, 3] to match counts.
counts = [[...]] # Shape [5, 7, 3]
dist.pdf(counts) # Shape [5, 7]Creates a 2-batch of 3-class distributions.
alpha = [[1, 2, 3], [4, 5, 6]] # Shape [2, 3]
dist = DirichletMultinomial(alpha)
# counts will be broadcast to [[11, 22, 33], [11, 22, 33]] to match alpha.
counts = [11, 22, 33]
dist.pdf(counts) # Shape [2]Initialize a batch of DirichletMultinomial distributions.
-
alpha: Shape[N1,..., Nn, k]positivefloatordoubletensor withn >= 0. Defines this as a batch ofN1 x ... x Nndifferentkclass Dirichlet multinomial distributions. -
Examples:
# Define 1-batch of 2-class Dirichlet multinomial distribution,
# also known as a beta-binomial.
dist = DirichletMultinomial([1.1, 2.0])
# Define a 2-batch of 3-class distributions.
dist = DirichletMultinomial([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])Parameters defining this distribution.
tf.contrib.distributions.DirichletMultinomial.log_pmf(counts, name=None) {#DirichletMultinomial.log_pmf}
Log(P[counts]), computed for every batch member.
For each batch of counts [c_1,...,c_k], P[counts] is the probability
that after sampling sum_j c_j draws from this Dirichlet Multinomial
distribution, the number of draws falling in class j is c_j. Note that
different sequences of draws can result in the same counts, thus the
probability includes a combinatorial coefficient.
counts: Non-negativefloat,double, orinttensor whose shape can be broadcast withself.alpha. For fixed leading dimensions, the last dimension represents counts for the corresponding Dirichlet Multinomial distribution inself.alpha.name: Name to give this Op, defaults to "log_pmf".
Log probabilities for each record, shape [N1,...,Nn].
Class means for every batch member.
Tensor providing number of classes in each batch member.
P[counts], computed for every batch member.
For each batch of counts [c_1,...,c_k], P[counts] is the probability
that after sampling sum_j c_j draws from this Dirichlet Multinomial
distribution, the number of draws falling in class j is c_j. Note that
different sequences of draws can result in the same counts, thus the
probability includes a combinatorial coefficient.
counts: Non-negativefloat,double, orinttensor whose shape can be broadcast withself.alpha. For fixed leading dimensions, the last dimension represents counts for the corresponding Dirichlet Multinomial distribution inself.alpha.name: Name to give this Op, defaults to "pmf".
Probabilities for each record, shape [N1,...,Nn].
Functions that transform conjugate prior/likelihood pairs to distributions representing the posterior or posterior predictive.
tf.contrib.distributions.normal_conjugates_known_sigma_posterior(prior, sigma, s, n) {#normal_conjugates_known_sigma_posterior}
Posterior Normal distribution with conjugate prior on the mean.
This model assumes that n observations (with sum s) come from a
Normal with unknown mean mu (described by the Normal prior)
and known variance sigma^2. The "known sigma posterior" is
the distribution of the unknown mu.
Accepts a prior Normal distribution object, having parameters
mu0 and sigma0, as well as known sigma values of the predictive
distribution(s) (also assumed Normal),
and statistical estimates s (the sum(s) of the observations) and
n (the number(s) of observations).
Returns a posterior (also Normal) distribution object, with parameters
(mu', sigma'^2), where:
mu ~ N(mu', sigma'^2)
sigma'^2 = 1/(1/sigma0^2 + n/sigma^2),
mu' = (mu0/sigma0^2 + s/sigma^2) * sigma'^2.
Distribution parameters from prior, as well as sigma, s, and n.
will broadcast in the case of multidimensional sets of parameters.
prior:Normalobject of typedtype: the prior distribution having parameters(mu0, sigma0).sigma: tensor of typedtype, taking valuessigma > 0. The known stddev parameter(s).s: Tensor of typedtype. The sum(s) of observations.n: Tensor of typeint. The number(s) of observations.
A new Normal posterior distribution object for the unknown observation
mean mu.
TypeError: if dtype ofsdoes not matchdtype, orprioris not a Normal object.
tf.contrib.distributions.normal_congugates_known_sigma_predictive(prior, sigma, s, n) {#normal_congugates_known_sigma_predictive}
Posterior predictive Normal distribution w. conjugate prior on the mean.
This model assumes that n observations (with sum s) come from a
Normal with unknown mean mu (described by the Normal prior)
and known variance sigma^2. The "known sigma predictive"
is the distribution of new observations, conditioned on the existing
observations and our prior.
Accepts a prior Normal distribution object, having parameters
mu0 and sigma0, as well as known sigma values of the predictive
distribution(s) (also assumed Normal),
and statistical estimates s (the sum(s) of the observations) and
n (the number(s) of observations).
Calculates the Normal distribution(s) p(x | sigma^2):
p(x | sigma^2) = int N(x | mu, sigma^2) N(mu | prior.mu, prior.sigma^2) dmu
= N(x | prior.mu, 1/(sigma^2 + prior.sigma^2))
Returns the predictive posterior distribution object, with parameters
(mu', sigma'^2), where:
sigma_n^2 = 1/(1/sigma0^2 + n/sigma^2),
mu' = (mu0/sigma0^2 + s/sigma^2) * sigma_n^2.
sigma'^2 = sigma_n^2 + sigma^2,
Distribution parameters from prior, as well as sigma, s, and n.
will broadcast in the case of multidimensional sets of parameters.
prior:Normalobject of typedtype: the prior distribution having parameters(mu0, sigma0).sigma: tensor of typedtype, taking valuessigma > 0. The known stddev parameter(s).s: Tensor of typedtype. The sum(s) of observations.n: Tensor of typeint. The number(s) of observations.
A new Normal predictive distribution object.
TypeError: if dtype ofsdoes not matchdtype, orprioris not a Normal object.