Google I/O returns May 18-20! Reserve space and build your schedule Register now


Joint density parameterized by a distribution-making generator.

This density enables unnormalized joint density computation from a single model specification.

A joint density is like a joint distribution, except we allow for a density to be unnormalized (total probability does not integrate to 1). As such, the log_prob method is not implemented; to compute the unnormalized log density, use method unnormalized_log_prob.

In addition to accepting the usual distributions like JointDistributionCoroutine, JointDensityCoroutine also accepts the distribution-like IncrementLogProb to adjust the overall unnormalized log-density in arbitrary ways.

As an example, suppose we wish to increase the log probability of a simple model. We might do so as follows:

tfd = tfp.distributions
tfde = tfp.experimental.distributions

Root = tfd.JointDistributionCoroutine.Root  # Convenient alias.
def model():
  w = yield Root(tfd.Normal(0., 1.))
  yield tfd.Normal(w, 1.)
  yield Root(tfde.IncrementLogProb(5.))

joint = tfd.JointDensityCoroutine(model)

x = joint.sample()
# ==> x is a length-3 tuple of Tensors representing a draw/realization from
#     each distribution, where the IncrementLogProb is represented by an
#     empty tensor (which is essentially a single nonvarying point).
# ==> A scalar `Tensor` representing the total log prob under the two
#     distributions, as well as including the offset effect of the
#     IncrementLogProb(5.).

*args Positional arguments forwarded to JointDistributionCoroutine.
name The name for ops managed by the density. Default value: JointDensityCoroutine.
**kwargs Named arguments forwarded to JointDistributionCoroutine.




View source

Generate samples of the specified shape.

Note that a call to sample() without arguments will generate a single sample.

sample_shape 0D or 1D int32 Tensor. Shape of the generated samples.
seed Python integer or tfp.util.SeedStream instance, for seeding PRNG.
name name to give to the op.
**kwargs Named arguments forwarded to subclass implementation.

samples a Tensor with prepended dimensions sample_shape.


View source

Unnormalized log probability density/mass function.

*args Positional arguments forwarded to superclass implementation, which likely include 'value' or possibly 'name'.
**kwargs Named arguments forwarded to superclass implementation.

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