JointDistribution#

class cuqi.distribution.JointDistribution(*densities)#

Joint distribution of multiple variables.

Parameters:

densities (RandomVariable or Density) – The densities to include in the joint distribution. Each density is passed as comma-separated arguments, and can be either a :class:’Density’ such as :class:’Distribution’ or RandomVariable.

Notes

The joint distribution allows conditioning on any variable of the distribution. This is useful for example when Gibbs sampling and the conditionals are needed. Conditioning essentially fixes the variable and stores its contribution to the log density function.

Example

Consider defining the joint distribution:

\[p(y,x,z) = p(y \mid x)p(x \mid z)p(z)\]

and conditioning on \(y=y_{obs}\) leading to the posterior:

\[p(x,z \mid y_{obs}) = p(y_{obs} \mid x)p(x \mid z)p(z)\]
import cuqi
import numpy as np

y_obs = np.random.randn(10)
A = np.random.randn(10,3)

# Define distributions for Bayesian model
y = cuqi.distribution.Normal(lambda x: A@x, np.ones(10))
x = cuqi.distribution.Normal(np.zeros(3), lambda z:z)
z = cuqi.distribution.Gamma(1, 1)

# Joint distribution p(y,x,z)
joint = cuqi.distribution.JointDistribution(y, x, z)

# Posterior p(x,z | y_obs)
posterior = joint(y=y_obs)
__init__(*densities)#

Create a joint distribution from the given densities.

Methods

__init__(*densities)

Create a joint distribution from the given densities.

get_density(name)

Return a density with the given name.

get_parameter_names()

Returns the parameter names of the joint distribution.

logd(*args, **kwargs)

Evaluate the un-normalized log density function.

Attributes

dim

Returns the dimensions of the joint distribution.

geometry

Returns the geometries of the joint distribution.