TransportMaps.Distributions.FactorizedDistributionBase
¶
Module Contents¶
Classes¶
Distribution \(\nu_\pi\) defiened by its conditional factors. |
- class TransportMaps.Distributions.FactorizedDistributionBase.FactorizedDistribution(factors)[source]¶
Bases:
TransportMaps.Distributions.DistributionBase.Distribution
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
oftuple
) – each tuple contains a factor (ConditionalDistribution
and/orDistribution
), 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)
- append(factor)[source]¶
Add a new factor to the distribution
- Parameters:
factor (
tuple
) – tuple containing a factor (ConditionalDistribution
and/orDistribution
), 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)
- 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:
- 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:
- 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:
- 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:
- 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 pointsdx (
ndarray
[\(m,d\)]) – direction on which to evaluate the Hessianparams (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 matchx.shape[0]
.cache (dict) – cache
- Returns:
- (
ndarray
[\(m,d,d\)]) – values of \(\nabla^2_x\log\pi\) at the
x
points.
- (