Attend the Women in ML Symposium on December 7

# tfp.substrates.jax.distributions.Inflated

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

A mixture of a point-mass and another distribution.

Inherits From: Mixture, Distribution

Under the hood, this is implemented as a mixture.Mixture, and so supports all of the methods of that class.

### Examples:

python


zinb = Inflated( tfd.NegativeBinomial(5.0, probs=0.1), inflated_loc_prob=0.2) sample = zinb.sample(seed=jax.random.PRNGKey(0)) 

If distribution is a CompositeTensors, then the resulting Inflated instance is a CompositeTensor as well. Otherwise, a non-CompositeTensor _Inflated instance is created instead. Distribution subclasses that inherit from Inflated will also inherit from CompositeTensor.

distribution The tfp.Distribution to combine with a point mass at x. This code is intended to be used only with discrete distributions; when used with continuous distributions sampling will work but log_probs will be a sum of values with different units.
inflated_loc_logits A scalar or tensor containing the excess log-odds for the point mass at inflated_loc. Only one of inflated_loc_probs or inflated_loc_logits should be passed in.
inflated_loc_probs A scalar or tensor containing the mixture weights for the point mass at inflated_loc. Only one of inflated_loc_probs or inflated_loc_logits should be passed in.
inflated_loc A scalar or tensor containing the locations of the point mass component of the mixture.
validate_args If true, inconsistent batch or event sizes raise a runtime error.
allow_nan_stats If false, any undefined statistics for any batch memeber raise an exception.
name An optional name for the distribution.

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.

cat

components

distribution The distribution used for the non-inflated part.
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_is_sharded

experimental_shard_axis_names The list or structure of lists of active shard axis names.
inflated_loc The location to add probability mass to.
inflated_loc_logits The log-odds for the point mass part of the distribution.
inflated_loc_probs The mixture weight(s) for the point mass part of the distribution.
name Name prepended to all ops created by this Distribution.
num_components

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.

trainable_variables

validate_args Python bool indicating possibly expensive checks are enabled.
variables

## 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 Python str prepended to names of ops created by this function.

Returns
cross_entropy self.dtype Tensor with shape [B1, ..., Bn] representing n different calculations of (Shannon) cross entropy.

### entropy

View source

Shannon entropy in nats.

### entropy_lower_bound

View source

A lower bound on the entropy of this mixture model.

The bound below is not always very tight, and its usefulness depends on the mixture probabilities and the components in use.

A lower bound is useful for ELBO when the Mixture is the variational distribution:

$$\log p(x) >= ELBO = \int q(z) \log p(x, z) dz + H[q]$$

where $$p$$ is the prior distribution, $$q$$ is the variational, and $$H[q]$$ is the entropy of $$q$$. If there is a lower bound $$G[q]$$ such that $$H[q] \geq G[q]$$ then it can be used in place of $$H[q]$$.

For a mixture of distributions $$q(Z) = \sum_i c_i q_i(Z)$$ with $$\sum_i c_i = 1$$, by the concavity of \( f(x) = -x \