particles.distributions.StructDist

class StructDist(laws)[source]

A distribution such that inputs/outputs are structured arrays.

A structured array is basically a numpy array with named fields. We use structured arrays to represent particles that are vectors of (named) parameters; see modules smc_samplers and mcmc. And we use StructDist to define prior distributions with respect to such parameters.

To specify a distribution such that parameters are independent, we pass a dictionary:

prior = StructDist({'mu':Normal(), 'sigma':Gamma(a=1., b=1.)})
# means mu~N(0,1), sigma~Gamma(1, 1) independently
x = prior.rvs(size=30)  # returns a structured array of length 30
print(x['sigma'])  # prints the 30 values for sigma

We may also define a distribution using a chain rule decomposition. For this, we pass an ordered dict, since the order of components become relevant:

chain_rule = OrderedDict()
chain_rule['mu'] = Normal()
chain_rule['tau'] = Cond(lambda x: Normal(loc=x['mu'])
prior = StructDist(chain_rule)
# means mu~N(0,1), tau|mu ~ N(mu,1)

In the third line, Cond is a ProbDist class that represents a conditionalp distribution; it is initialized with a function that returns for each x a distribution that may depend on fields in x.

Parameters:

laws (dict or ordered dict (as explained above)) – keys are parameter names, values are ProbDist objects

__init__(laws)[source]

Methods

__init__(laws)

logpdf(theta)

pdf(x)

ppf(u)

rvs([size])

shape(size)

Attributes

dim