# TransportMaps.Distributions.FactorizedDistributionBase¶

## Module Contents¶

### Classes¶

 FactorizedDistribution Distribution $$\nu_\pi$$ defiened by its conditional factors.
class TransportMaps.Distributions.FactorizedDistributionBase.FactorizedDistribution(factors)[source]

Distribution $$\nu_\pi$$ defiened by its conditional factors.

The density of the distribution $$\nu_\pi$$ is defined by

$\pi({\bf x}) = \prod_{({\bf i},{\bf k}) \in \mathcal{I}} \pi({\bf x}_{\bf i},{\bf x}_{\bf k})$
Parameters:

factors (list of tuple) – each tuple contains a factor (ConditionalDistribution and/or Distribution), and two lists containing the list of marginal variables and conditioning variables

Example

Let $$\pi(x_0,x_1,x_2) = \pi_1(x_2|x_1,x_0) \pi_2(x_0|x_1) \pi_3(x_1)$$.

>>> factors = [(p1, [2], [1,0] ),
>>>            (p2, [0], [1]  ),
>>>            (p3, [1], []    )]
>>> pi = FactorizedDistribution(factors)

property var_to_factor_map[source]
property n_factors[source]
get_ncalls_tree(indent='')[source]
get_nevals_tree(indent='')[source]
get_teval_tree(indent='')[source]
update_ncalls_tree(obj)[source]
update_nevals_tree(obj)[source]
update_teval_tree(obj)[source]
reset_counters()[source]
append(factor)[source]

Add a new factor to the distribution

Parameters:

factor (tuple) – tuple containing a factor (ConditionalDistribution and/or Distribution), and two tuples with the list of marginal variables and conditioning variables

Example

Let $$\pi(x_0,x_1,x_2) = \pi_1(x_2|x_1,x_0) \pi_2(x_0|x_1) \pi_3(x_1)$$ and let’s add the factor $$\pi_4(x_3|x_0,x_1,x_2)$$, obtaining:

$\pi(x_0,x_1,x_2,x_3) = \pi_4(x_3|x_0,x_1,x_2)\pi_1(x_2|x_1,x_0) \pi_2(x_0|x_1) \pi_3(x_1)$
>>> factor = (pi4, [3], [0,1,2])
>>> pi.append(factor)

update_var_to_factor_map()[source]
rvs(m, *args, **kwargs)[source]

[Abstract] Generate $$m$$ samples from the distribution.

Parameters:

m (int) – number of samples to generate

Returns:

(ndarray [$$m,d$$]) – $$m$$

$$d$$-dimensional samples

Raises:

NotImplementedError – the method needs to be defined in the sub-classes

log_pdf(x, params=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate $$\log \pi({\bf x})$$

Parameters:
• x (ndarray [$$m,d$$]) – evaluation points

• params (dict) – parameters

• idxs_slice (slice) – if precomputed values are present, this parameter indicates at which of the points to evaluate. The number of indices represented by idxs_slice must match x.shape[0].

• cache (dict) – cache

Returns:

(ndarray [$$m$$]) – values of $$\log\pi$$

at the x points.

grad_x_log_pdf(x, params=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate $$\nabla_{\bf x} \log \pi({\bf x})$$

Parameters:
• x (ndarray [$$m,d$$]) – evaluation points

• params (dict) – parameters

• idxs_slice (slice) – if precomputed values are present, this parameter indicates at which of the points to evaluate. The number of indices represented by idxs_slice must match x.shape[0].

• cache (dict) – cache

Returns:

(ndarray [$$m,d$$]) – values of

$$\nabla_x\log\pi$$ at the x points.

tuple_grad_x_log_pdf(x, params=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate $$\log \pi({\bf x}), \nabla_{\bf x} \log \pi({\bf x})$$

Parameters:
• x (ndarray [$$m,d$$]) – evaluation points

• params (dict) – parameters

• idxs_slice (slice) – if precomputed values are present, this parameter indicates at which of the points to evaluate. The number of indices represented by idxs_slice must match x.shape[0].

• cache (dict) – cache

Returns:

(tuple) – function and gradient evaluation

hess_x_log_pdf(x, params=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate $$\nabla^2_{\bf x} \log \pi({\bf x})$$

Parameters:
• x (ndarray [$$m,d$$]) – evaluation points

• params (dict) – parameters

• idxs_slice (slice) – if precomputed values are present, this parameter indicates at which of the points to evaluate. The number of indices represented by idxs_slice must match x.shape[0].

• cache (dict) – cache

Returns:

(ndarray [$$m,d,d$$]) – values of

$$\nabla^2_x\log\pi$$ at the x points.

action_hess_x_log_pdf(x, dx, params=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate $$\nabla^2_{\bf x} \log \pi({\bf x})$$

Parameters:
• x (ndarray [$$m,d$$]) – evaluation points

• dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian

• params (dict) – parameters

• idxs_slice (slice) – if precomputed values are present, this parameter indicates at which of the points to evaluate. The number of indices represented by idxs_slice must match x.shape[0].

• cache (dict) – cache

Returns:

(ndarray [$$m,d,d$$]) – values of

$$\nabla^2_x\log\pi$$ at the x` points.