Attend the Women in ML Symposium on December 7

# tfp.substrates.jax.distributions.ZeroInflatedNegativeBinomial

A mixture of a point-mass and another distribution.

Inherits From: Inflated, 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.

allow_nan_stats

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.
logits

name Name prepended to all ops created by this Distribution.
num_components

parameters Dictionary of parameters used to instantiate this Distribution.
probs

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.

require_integer_total_count

self

total_count

trainable_variables

validate_args

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 \log x$$, a simple lower bound is:

\begin{align} H[q] & = - \int q(z) \log q(z) dz \\\ & = - \int (\sum_i c_i q_i(z)) \log(\sum_i c_i q_i(z)) dz \\\ & \geq - \sum_i c_i \int q_i(z) \log q_i(z) dz \\\ & = \sum_i c_i H[q_i] \end{align}

This is the term we calculate below for $$G[q]$$.

Args
name A name for this operation (optional).

Returns
A lower bound on the Mixture's entropy.

### event_shape_tensor

View source

Shape of a single sample from a single batch as a 1-D int32 Tensor.

Args
name name to give to the op

Returns
event_shape Tensor.

### experimental_default_event_space_bijector

View source

Bijector mapping the reals (R**n) to the event space of the distribution.

Distributions with continuous support may implement _default_event_space_bijector which returns a subclass of tfp.bijectors.Bijector that maps R**n to the distribution's event space. For example, the default bijector for the Beta distribution is