# TransportMaps.Maps¶

Sub-modules

Classes Class Description
Map Abstract map $$T:\mathbb{R}^{d_x}\rightarrow\mathbb{R}^{d_y}$$
ParametricMap Abstract map $$T:\mathbb{R}^{d_a}\times\mathbb{R}^{d_x}\rightarrow\mathbb{R}^{d_y}$$
LinearMap Map $$T({\bf x}) = {\bf c} + {\bf T} {\bf x}$$
ConditionallyLinearMap Map $$T:\mathbb{R}^{d_x}\times\mathbb{R}^{d_a}\rightarrow\mathbb{R}^{d_y}$$ defined by $$T({\bf x};{\bf a}) = {\bf c}({\bf a}) + {\bf T}({\bf a}) {\bf x}$$
ConstantMap Map $$T({\bf x})={\bf c}$$
CompositeMap Given maps $$T_1,T_2$$, define map $$T=T_1 \circ T_2$$.
ListCompositeMap Construct the composite map $$T_1 \circ T_2 \circ \cdots \circ T_n$$
ListStackedMap Defines the map $$T$$ obtained by stacking $$T_1, T_2, \ldots$$.
TransportMap Transport map $$T({\bf x},{\bf a})$$.
InverseTransportMap Given the transport map $$T$$, define $$S=T^{-1}$$.
CompositeTransportMap
ListCompositeTransportMap
ListStackedTransportMap
IdentityTransportMap Map $$T({\bf x})={\bf x}$$.
PermutationTransportMap Map $$T({\bf x}) = [x_{p(0)}, \ldots, x_{p(d)}]^T$$
LinearTransportMap Linear map $$T({\bf x})={\bf c} + {\bf L}{\bf x}$$
TriangularTransportMap Generalized triangular transport map $$T({\bf x},{\bf a})$$.
MonotonicTriangularTransportMap [Abstract] Triangular transport map which is monotone by construction.
TriangularListStackedTransportMap Triangular transport map obtained by stacking $$T_1, T_2, \ldots$$.
FrozenLinearDiagonalTransportMap Linear diagonal transport map $$(x_1,\ldots,x_d) \rightarrow (a_1+b_1 x_1, \ldots, a_d + b_d x_d)$$
FrozenExponentialDiagonalTransportMap Exponential diagonal transport map $$(x_1,\ldots,x_d) \rightarrow (\exp(x_1), \ldots, \exp(x_d))$$
FrozenGaussianToUniformDiagonalTransportMap Gaussian to Uniform diagonal transport map $$(x_1,\ldots,x_d) \rightarrow (\frac{1}{2}[1+{\rm erf}(x_1/\sqrt{2})], \ldots, \frac{1}{2}[1+{\rm erf}(x_d/\sqrt{2})])$$
FrozenBananaMap
IntegratedExponentialTriangularTransportMap Triangular transport map where each component is represented by an IntegratedExponential function.
CommonBasisIntegratedExponentialTriangularTransportMap Triangular transport map $$T$$ where the beases of each component $$T_i$$ are the same for corresponding dimensions.
IntegratedSquaredTriangularTransportMap Triangular transport map where each component is represented by an IntegratedSquaredLinearSpanApproximation function.
LinearSpanTriangularTransportMap Triangular transport map where each component is represented by an FunctionalApproximations.LinearSpanApproximation function.
CommonBasisLinearSpanTriangularTransportMap Triangular transport map $$T$$ where the beases of each component $$T_i$$ are the same for corresponding dimensions.
MonotonicLinearSpanTriangularTransportMap Triangular transport map where each component is represented by an FunctionalApproximations.MonotonicLinearSpanApproximation function.
MonotonicCommonBasisLinearSpanTriangularTransportMap Triangular transport map $$T$$ where the beases of each component $$T_i$$ are the same for corresponding dimensions.

Documentation

class TransportMaps.Maps.Map(dim_in, dim_out)[source]

Abstract map $$T:\mathbb{R}^{d_x}\rightarrow\mathbb{R}^{d_y}$$

Parameters: dim_in (int) – input dimension $$d_x$$ dim_out (int) – output dimension $$d_y$$
action_hess_x(x, dx, precomp=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate the action of the Hessian $$\langle\nabla^2_{\bf x}T,\delta{\bf x}\rangle$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points dx (ndarray [$$m,d_x$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
action_hess_x_log_pullback(x, pi, dx, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None, *args, **kwargs)[source]

Compute $$\langle\nabla^2_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right],\delta{\bf x}\rangle$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,d,d$$]) – $$\langle\nabla^2_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right],\delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_x_log_pushforward(x, pi, dx, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\langle \nabla^2_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right],\delta{\bf x}\rangle$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,d$$]) – $$\langle \nabla^2_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right],\delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_x_log_pushforward(), log_pushforward(), grad_x_inverse(), hess_x_inverse() and hess_x_log_det_grad_x_inverse().

evaluate(x, precomp=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate the map $$T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x(x, precomp=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None, *args, **kwargs)[source]

Compute: $$\nabla_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_pullback(), grad_x() and grad_x_log_det_grad_x().

grad_x_log_pushforward(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute: $$\nabla_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right]$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_pushforward(), grad_x_inverse() and grad_x_log_det_grad_x_inverse().

hess_x(x, precomp=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate the Hessian $$\nabla^2_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
hess_x_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_log_pushforward(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right]$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_x_log_pushforward(), log_pushforward(), grad_x_inverse(), hess_x_inverse() and hess_x_log_det_grad_x_inverse().

log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. cache (dict) – cache (ndarray [$$m$$]) – $$\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
log_pushforward(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\log \pi \circ T^{-1}({\bf x},{\bf a}) + \log \vert \det D T^{-1}({\bf y},{\bf a}) \vert$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m$$]) – $$\log \pi \circ T^{-1}({\bf x},{\bf a}) + \log \vert \det D T^{-1}({\bf y},{\bf a}) \vert$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cached=None)[source]

Compute: $$\pi \circ T({\bf x,a}) \vert\det \grad_{\bf x}T({\bf x,a})\vert$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. cache (dict) – cache (ndarray [$$m$$]) – $$\pi \circ T({\bf x,a}) \vert\det \grad_{\bf x}T({\bf x,a})\vert$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
pushforward(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\pi \circ T_{\bf a}^{-1}({\bf y}) \vert\det \grad_{\bf x}T_{\bf a}^{-1}({\bf y})\vert$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pushed forward params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. cache (dict) – cache (ndarray [$$m$$]) – $$\pi \circ T^{-1}({\bf y,a}) \vert\det \grad_{\bf x}T^{-1}({\bf y,a})\vert$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
tuple_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate the function and gradient.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (tuple) – function and gradient evaluation NotImplementedError – to be implemented in sub-classes
tuple_grad_x_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None, *args, **kwargs)[source]

Compute: $$\left(\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert, \nabla_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]\right)$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (tuple) – $$\left(\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert, \nabla_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]\right)$$ ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_pullback(), grad_x() and grad_x_log_det_grad_x().

tuple_grad_x_log_pushforward(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute: $$\left(\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert, \nabla_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right]\right)$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (tuple) – $$\left(\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert, \nabla_{\bf x}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right]\right)$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_pushforward(), grad_x_inverse() and grad_x_log_det_grad_x_inverse().

class TransportMaps.Maps.ParametricMap(dim_in, dim_out)[source]

Abstract map $$T:\mathbb{R}^{d_a}\times\mathbb{R}^{d_x}\rightarrow\mathbb{R}^{d_y}$$

Parameters: dim_in (int) – input dimension $$d_x$$ dim_out (int) – output dimension $$d_y$$
action_hess_a(x, da, precomp=None, idxs_slice=slice(None, None, None))[source]

Compute $$\langle\nabla^2_{\bf a} T({\bf x},{\bf a}), \delta{\bf a}\rangle$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points da (ndarray [$$N$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray) – action of the Hessian NotImplementedError – needs to be implemented in subclasses
coeffs

Returns the actual value of the coefficients.

Returns: (ndarray [$$N$$]) – coefficients. NotImplementedError – needs to be implemented in subclasses
grad_a(x, precomp=None, idxs_slice=slice(None, None, None))[source]

Compute $$\nabla_{\bf a} T({\bf x},{\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray) – gradient NotImplementedError – needs to be implemented in subclasses
hess_a(x, precomp=None, idxs_slice=slice(None, None, None))[source]

Compute $$\nabla^2_{\bf a} T({\bf x},{\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray) – Hessian NotImplementedError – needs to be implemented in subclasses
n_coeffs

Returns the total number of coefficients.

Returns: (int) – total number $$N$$ of coefficients characterizing the map. NotImplementedError – needs to be implemented in subclasses
class TransportMaps.Maps.LinearMap(c, T)[source]

Map $$T({\bf x}) = {\bf c} + {\bf T} {\bf x}$$

Parameters: c (ndarray [$$d_y$$]) – constant part T (ndarray [$$d_y,d_x$$]) – linear part (matrix)
action_hess_x(x, dx, *args, **kwargs)[source]

[Abstract] Evaluate the action of the Hessian $$\langle\nabla^2_{\bf x}T,\delta{\bf x}\rangle$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points dx (ndarray [$$m,d_x$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
evaluate(x, *args, **kwargs)[source]

[Abstract] Evaluate the map $$T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
hess_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the Hessian $$\nabla^2_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.ConditionallyLinearMap(c, T, coeffs=None)[source]

Map $$T:\mathbb{R}^{d_x}\times\mathbb{R}^{d_a}\rightarrow\mathbb{R}^{d_y}$$ defined by $$T({\bf x};{\bf a}) = {\bf c}({\bf a}) + {\bf T}({\bf a}) {\bf x}$$

Parameters: c (Map) – map $${\bf c}:\mathbb{R}^{d_a}\rightarrow\mathbb{R}^{d_y}$$ T (Map) – map $${\bf T}:\mathbb{R}^{d_a}\rightarrow\mathbb{R}^{d_y\times d_x}$$ coeffs (ndarray) – fixing the coefficients $${\bf a}$$ defining $${\bf c}({\bf a})$$ and $${\bf T}({\bf a})$$.
coeffs

Returns the actual value of the coefficients.

Returns: (ndarray [$$N$$]) – coefficients.
evaluate(x, precomp=None, idxs_slice=slice(None, None, None))[source]

Evaluate the map $$T$$ at the points $${\bf x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points
grad_x(x, precomp=None, idxs_slice=slice(None, None, None))[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.ConstantMap(dim_in, const)[source]

Map $$T({\bf x})={\bf c}$$

Parameters: dim_in (int) – input dimension $$d_x$$ const (ndarray) – constant $${\bf c}$$
evaluate(x, precomp=None, idxs_slice=slice(None, None, None))[source]

[Abstract] Evaluate the map $$T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x(x, precomp=None, idxs_slice=slice(None, None, None))[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
hess_x(x, precomp=None, idxs_slice=slice(None, None, None))[source]

[Abstract] Evaluate the Hessian $$\nabla^2_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.CompositeMap(t1, t2)[source]

Given maps $$T_1,T_2$$, define map $$T=T_1 \circ T_2$$.

Parameters: t1 (Map) – map $$T_1$$ t2 (Map) – map $$T_2$$
action_hess_x_log_det_grad_x(x, dx, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values (ndarray [$$m,d$$]) – $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

action_hess_x_log_det_grad_x_inverse(x, dx, precomp=None, *args, **kwargs)[source]

Compute: $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a}), \delta{\bf x}\rangle$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d$$]) – $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a}), \delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_det_grad_x() and grad_x_log_det_grad_x().

hess_x_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

For the transport maps $$T_1,T_2$$,

$\nabla^2_{\bf x} \log \det \nabla_{\bf x} (T_1 \circ T_2) = \left[ \nabla^2_{\bf x} \log \det (\nabla_{\bf x} T_1 \circ T_2) \cdot \nabla_{\bf x} T_2 + \nabla_{\bf x} \log \det \nabla_{\bf x} T_2 \right] \cdot (\nabla_{\bf x} T_2) + \nabla_{\bf x} \log \det (\nabla_{\bf x} T_1 \circ T_2) \cdot \nabla^2_{\bf x} T_2 + \nabla^2_{\bf x} \log \det \nabla_{\bf x} T_2$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_det_grad_x() and grad_x_log_det_grad_x().

hess_x_log_det_grad_x_inverse(x, precomp=None, *args, **kwargs)[source]

Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_det_grad_x() and grad_x_log_det_grad_x().

class TransportMaps.Maps.ListCompositeMap(tm_list)[source]

Construct the composite map $$T_1 \circ T_2 \circ \cdots \circ T_n$$

Parameters: tm_list (list) – list of transport maps $$[T_1,\ldots,T_n]$$
..warning:: This should become the standard CompositeTransportMap, thus
replacing the actual implementation.
action_hess_x(x, dx, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\langle\nabla^2_{\bf x} T({\bf x},{\bf a}), \delta{\bf x}\rangle$$.

Apply chain rule.

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d$$]) – action of the Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_x_inverse(x, dx, *args, **kwargs)[source]

Compute $$\langle\nabla^2_{\bf x} T^{-1}({\bf x},{\bf a}), \delta{\bf x}\rangle$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d,d$$]) – action of the Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
coeffs

Returns the actual value of the coefficients.

Returns: (ndarray [$$N$$]) – coefficients.
evaluate(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate the transport map at the points $${\bf x} \in \mathbb{R}^{m \times d}$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – transformed points ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\nabla_{\bf x} T({\bf x},{\bf a})$$.

Apply chain rule.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d$$]) – gradient matrices for every evaluation point. ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x_inverse(x, *args, **kwargs)[source]

Compute $$\nabla_{\bf x} T^{-1}({\bf x},{\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (ndarray [$$m,d,d$$]) – gradient matrices for every evaluation point.
grad_x_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_x_log_det_grad_x_inverse(x, precomp=None, *args, **kwargs)[source]

Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point
hess_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\nabla^2_{\bf x} T({\bf x},{\bf a})$$.

Apply chain rule.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_inverse(x, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x} T^{-1}({\bf x},{\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
inverse(x, *args, **kwargs)[source]

Compute: $$T^{-1}({\bf y},{\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points (ndarray [$$m,d$$]) – $$T^{-1}({\bf y},{\bf a})$$ for every evaluation point
log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

For the transport maps $$T_1,T_2$$,

$\log \det \nabla_{\bf x} (T_1 \circ T_2)({\bf x}) = \log \det \nabla_{\bf x} T_1 ({\bf y}) + \log \det \nabla_{\bf x} T_2({\bf x})$

where $${\bf y} = T_2({\bf x})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point
log_det_grad_x_inverse(x, precomp=None, *args, **kwargs)[source]

Compute: $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point
n_coeffs

Returns the total number of coefficients.

Returns: total number $$N$$ of coefficients characterizing the transport map.
tuple_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate the function and gradient.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (tuple) – function and gradient evaluation
class TransportMaps.Maps.ListStackedMap(tm_list)[source]

Defines the map $$T$$ obtained by stacking $$T_1, T_2, \ldots$$.

$\begin{split}T({\bf x}) = \left[ \begin{array}{c} T_1({\bf x}_{0:d_1}) \\ T_2({\bf x}_{0:d_2}) \\ \vdots \end{array} \right]\end{split}$
Parameters: tm_list (list of Map) – list of transport maps $$T_i$$
evaluate(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

[Abstract] Evaluate the map $$T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
hess_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

[Abstract] Evaluate the Hessian $$\nabla^2_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.TransportMap(active_vars, approx_list)[source]

Transport map $$T({\bf x},{\bf a})$$.

For $${\bf x} \in \mathbb{R}^d$$, and parameters $${\bf a} \in \mathbb{R}^N$$, the parametric transport map is given by

$\begin{split}T({\bf x},{\bf a}) = \begin{bmatrix} T_1 \left({\bf x}, {\bf a}^{(1)}\right) \\ T_2 \left({\bf x}, {\bf a}^{(2)}\right) \\ T_3 \left({\bf x}, {\bf a}^{(3)}\right) \\ \vdots \\ T_d \left({\bf x}, {\bf a}^{(d)}\right) \end{bmatrix}\end{split}$

where $${\bf a}^{(i)} \in \mathbb{R}^{n_i}$$ and $$\sum_{i=1}^d n_i = N$$.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.MonotonicFunctionApproximation) – list of monotonic functional approximations for each dimension
action_hess_a(x, da, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\langle\nabla^2_{\bf a} T({\bf x},{\bf a}), \delta{\bf a}\rangle$$.

As in the case of grad_a(), the :math:d times N  actions of the Hessian of T({bf x},{bf a}) is (hyper) block diagonal.

Parameters: x (ndarray [$$m,d$$]) – evaluation points da (ndarray [$$N$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (list of ndarray [$$n_i,n_i$$]) – list containing $$\langle\nabla^2_{{\bf a}^{(1)}} T_1 ({\bf x}_1, {\bf a}^{(1)}),\delta{\bf a}^{(1)}\rangle$$, $$\langle\nabla^2_{{\bf a}^{(2)}} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)}),\delta{\bf a}^{(2)}\rangle$$, etc. ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_a_log_pullback(x, pi, da, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\langle\nabla^2_{\bf a}[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert ], \delta{\bf a}\rangle$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back da (ndarray [$$N$$]) – direction on which to evaluate the Hessian params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. cache (dict) – cache (ndarray [$$m,N,N$$]) – $$\langle\nabla^2_{\bf a}[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert ], \delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_a(), hess_a(), grad_x_log_pullback(), hess_x_log_pullback(), hess_a_log_det_grad_x().

action_hess_x(x, dx, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\langle\nabla^2_{\bf x} T({\bf x},{\bf a}),\delta{\bf x}\rangle$$.

This is the tensor

$\left[\nabla^2_{\bf x} T({\bf x},{\bf a})\right]_{i,k,:i} = \langle \nabla^2_{\bf x} T_k({\bf x}^{(i)},{\bf a}^{(k)}), \delta{\bf x}\rangle$
Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
coeffs

Returns the actual value of the coefficients.

Returns: (ndarray [$$N$$]) – coefficients.
det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point
evaluate(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Evaluate the transport map at the points $${\bf x} \in \mathbb{R}^{m \times d}$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,d$$]) – transformed points ValueError – if $$d$$ does not match the dimension of the transport map.
get_identity_coeffs()[source]

[Abstract] Returns the coefficients corresponding to the identity map

Returns: coefficients (ndarray [$$N$$]) NotImplementedError – must be implemented in subclasses.
grad_a(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\nabla_{\bf a} T({\bf x},{\bf a})$$

By the definition of the transport map $$T({\bf x},{\bf a})$$, the components $$T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, … are defined by different sets of parameters $${\bf a}^{(1)}$$, $${\bf a}^{(2)}$$, etc.

For this reason $$\nabla_{\bf a} T({\bf x},{\bf a})$$ is block diagonal:

\nabla_a T({\bf x},{\bf a}) = \begin{bmatrix} \left[ \nabla_{{\bf a}^{(1)}} T_1 ({\bf x}_1, {\bf a}^{(1)}) \right]^T & {\bf 0} & \cdots \\ {\bf 0} & \left[ \nabla_{{\bf a}^{(2)}} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)}) \right]^T & \\ \vdots & & \ddots \end{bmatrix}

Consequentely this function will return only the diagonal blocks of the gradient.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dics) – cache (list of ndarray [$$n_i$$]) – list containing $$\nabla_{{\bf a}^{(1)}} T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$\nabla_{{\bf a}^{(2)}} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, etc. ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla_{\bf a} \nabla_{\bf x} T({\bf x},{\bf a})$$

By the definition of the transport map $$T({\bf x},{\bf a})$$, the components $$T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, … are defined by different sets of parameters $${\bf a}^{(1)}$$, $${\bf a}^{(2)}$$, etc.

For this reason $$\nabla_{\bf a} \nabla_{\bf x} T({\bf x},{\bf a})$$ is block diagonal:

\nabla_a \nabla_{\bf x} T({\bf x},{\bf a}) = \begin{bmatrix} \left[ \nabla_{{\bf a}^{(1)}} \nabla_{\bf x}_1 T_1 ({\bf x}_1, {\bf a}^{(1)}) \right]^T & {\bf 0} & \cdots \\ {\bf 0} & \left[ \nabla_{{\bf a}^{(2)}} \nabla_{\bf x}_{1:2} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)}) \right]^T & \\ \vdots & & \ddots \end{bmatrix}

Consequentely this function will return only the diagonal blocks of the gradient.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (list of ndarray [$$n_i$$]) – list containing $$\nabla_{{\bf a}^{(1)}} \nabla_{\bf x}_1 T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$\nabla_{{\bf a}^{(2)}} \nabla_{\bf x}_{1:2} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, etc. ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_hess_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla_{\bf a} \nabla^2_{\bf x} T({\bf x},{\bf a})$$.

By the definition of the transport map $$T({\bf x},{\bf a})$$, the components $$T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, … are defined by different sets of parameters $${\bf a}^{(1)}$$, $${\bf a}^{(2)}$$, etc.

For this reason $$\nabla_{\bf a} \nabla^2_{\bf x} T({\bf x},{\bf a})$$ is block diagonal:

\nabla_a \nabla^2_{\bf x} T({\bf x},{\bf a}) = \begin{bmatrix} \left[ \nabla_{{\bf a}^{(1)}} \nabla^2_{\bf x}_1 T_1 ({\bf x}_1, {\bf a}^{(1)}) \right]^T & {\bf 0} & \cdots \\ {\bf 0} & \left[ \nabla_{{\bf a}^{(2)}} \nabla^2_{\bf x}_{1:2} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)}) \right]^T & \\ \vdots & & \ddots \end{bmatrix}

Consequentely this function will return only the diagonal blocks of the hessian.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (list of ndarray [$$n_i$$]) – list containing $$\nabla_{{\bf a}^{(1)}} \nabla^2_{\bf x}_1 T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$\nabla_{{\bf a}^{(2)}} \nabla^2_{\bf x}_{1:2} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, etc. ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_hess_x_log_pullback(pi, x, params_t=None, params_pi=None, idxs_slice=slice(None, None, None))[source]

Compute $$\nabla_{\bf a} \nabla^2_{\bf x}[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert ]$$.

Parameters: pi (Distributions.Distribution) – distribution to be pulled back x (ndarray [$$m,d$$]) – evaluation points params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,N,d,d$$]) – $$\nabla_{\bf a} \nabla^2_{\bf x}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_a(), hess_a(), grad_x_log_pullback(), hess_x_log_pullback(), hess_a_log_det_grad_x().

grad_a_inverse(x, precomp=None, idxs_slice=slice(None, None, None))[source]

[Abstract] Compute $$\nabla_{\bf a} T^{-1}({\bf x},{\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,N$$]) – $$\nabla_{\bf a} T^{-1}({\bf x},{\bf a})$$ ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\nabla_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,N$$]) – $$\nabla_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point
grad_a_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\nabla_{\bf a}[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert ]$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,N$$]) – $$\nabla_{\bf a}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_log_pushforward(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla_{\bf a}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \det \nabla_{\bf x}T^{-1}({\bf x,a}) \right]$$ .

For $${\bf z} = T^{-1}({\bf x,a})$$,

$\begin{split}\nabla_{\bf a}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \det \nabla_{\bf x}T^{-1}({\bf x,a}) \right] &= \nabla_{\bf a} T({\bf z, a})^\top \nabla_{\bf x} T({\bf z,a})^{-\top} \left( \sum_{i=1}^d \frac{\nabla_{\bf x}\partial_{x_i}T_i({\bf z}_{1:i},{\bf a}_i)}{\partial_{x_i}T_i({\bf z}_{1:i},{\bf a}_i)} - \nabla_{\bf x}\log\pi \right) \\ & - \sum_{i=1}^d \frac{\nabla_{\bf a}\partial_{x_i}T_i({\bf z}_{1:i},{\bf a}_i)}{\partial_{x_i}T_i({\bf z}_{1:i},{\bf a}_i)}\end{split}$
Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. (ndarray [$$m,N$$]) – $$\nabla_{\bf a}\left[ \log \pi \circ T^{-1}({\bf x,a}) + \log \vert\det \nabla_{\bf x}T^{-1}({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_a_inverse(), grad_a_log_det_grad_x_inverse().

grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla_{\bf x} T({\bf x},{\bf a})$$.

This is

\nabla_{\bf x} T({\bf x},{\bf a}) = \begin{bmatrix} \nabla_{\bf x} T_1({\bf x},{\bf a}) \\ \nabla_{\bf x} T_2({\bf x},{\bf a}) \\ \vdots \\ \nabla_{\bf x} T_d({\bf x},{\bf a}) \end{bmatrix}

for every evaluation point.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – gradient matrices for every evaluation point. ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x_inverse(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute $$\nabla_{\bf x} T^{-1}({\bf x},{\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – gradient matrices for every evaluation point. NotImplementedError – to be implemented in subclasses
grad_x_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point

See also

grad_x_log_det_grad_x_inverse(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point

See also

hess_a(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\nabla^2_{\bf a} T({\bf x},{\bf a})$$.

As in the case of grad_a(), the $$d \times N \times N$$ Hessian of T({bf x},{bf a}) is (hyper) block diagonal.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (list of ndarray [$$n_i,n_i$$]) – list containing $$\nabla^2_{{\bf a}^{(1)}} T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$\nabla^2_{{\bf a}^{(2)}} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, etc. ValueError – if $$d$$ does not match the dimension of the transport map.
hess_a_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\nabla^2_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,N,N$$]) – $$\nabla^2_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point
hess_a_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\nabla^2_{\bf a}[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert ]$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. cache (dict) – cache (ndarray [$$m,N,N$$]) – $$\nabla^2_{\bf a}\left[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_a(), hess_a(), grad_x_log_pullback(), hess_x_log_pullback(), hess_a_log_det_grad_x().

hess_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x} T({\bf x},{\bf a})$$.

This is the tensor

$\left[\nabla^2_{\bf x} T({\bf x},{\bf a})\right]_{i,k,:,:} = \nabla^2_{\bf x} T_k({\bf x}^{(i)},{\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point
hess_x_log_det_grad_x_inverse(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point
inverse(y, precomp=None, idxs_slice=slice(None, None, None))[source]

[Abstract] Compute: $$T^{-1}({\bf y},{\bf a})$$

Parameters: y (ndarray [$$m,d$$]) – evaluation points precomp (dict) – precomputed values 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. (ndarray [$$m,d$$]) – $$T^{-1}({\bf y},{\bf a})$$ for every evaluation point
log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point
log_det_grad_x_inverse(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Compute: $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point
minimize_kl_divergence(d1, d2, qtype=None, qparams=None, x=None, w=None, params1=None, params2=None, x0=None, regularization=None, tol=0.0001, maxit=100, ders=2, fungrad=False, precomp_type='uni', batch_size=None, nprocs=None, grad_check=False, hess_check=False)[source]

[Abstract] Compute: $${\bf a}^* = \arg\min_{\bf a}\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$

Parameters: d1 (Distribution) – distribution $$\pi_1$$ d2 (Distribution) – distribution $$\pi_2$$ qtype (int) – quadrature type number provided by $$\pi$$ qparams (object) – inputs necessary to the generation of the selected quadrature x (ndarray [$$m,d$$]) – quadrature points w (ndarray [$$m$$]) – quadrature weights params1 (dict) – parameters for distribution $$\pi_1$$ params2 (dict) – parameters for distribution $$\pi_2$$ x0 (ndarray [$$N$$]) – coefficients to be used as initial values for the optimization regularization (dict) – defines the regularization to be used. If None, no regularization is applied. If key type=='L2' then applies Tikonhov regularization with coefficient in key alpha. tol (float) – tolerance to be used to solve the KL-divergence problem. maxit (int) – maximum number of iterations ders (int) – order of derivatives available for the solution of the optimization problem. 0 -> derivative free, 1 -> gradient, 2 -> hessian. fungrad (bool) – whether the distributions $$\pi_1,\pi_2$$ provide the method Distribution.tuple_grad_x_log_pdf() computing the evaluation and the gradient in one step. This is used only for ders==1. precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ batch_size (list [3 or 2] of int) – the list contains the size of the batch to be used for each iteration. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. nprocs (int) – number of processors to be used for function evaluation, gradient evaluation and Hessian evaluation. Value None will determine the MPI size automatically (or set to nprocs=1 if MPI is not supported) grad_check (bool) – whether to use finite difference to check the correctness of of the gradient hess_check (bool) – whether to use finite difference to check the correctenss of the Hessian log informations from the solver log (dict)

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

minimize_kl_divergence_action_hess_a_objective(a, da, params)[source]

Action of the Hessian of the objective function $$\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$ on the direction v

Parameters: a (ndarray [$$N$$]) – coefficients da (ndarray [$$N$$]) – vector on which to apply the Hessian params (dict) – dictionary of parameters
minimize_kl_divergence_action_storage_hess_a_objective(a, v, params)[source]

Assemble the Hessian $$\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$ and compute its action on the vector $$v$$, for the KL-divergence minimization problem.

Parameters: a (ndarray [$$N$$]) – coefficients v (ndarray [$$N$$]) – vector on which to apply the Hessian params (dict) – dictionary of parameters
minimize_kl_divergence_grad_a_objective(a, params)[source]

Gradient of the objective function $$\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$ for the KL-divergence minimization.

Parameters: a (ndarray [$$N$$]) – coefficients params (dict) – dictionary of parameters
minimize_kl_divergence_hess_a_objective(a, params)[source]

Hessian of the objective function $$\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$ for the KL-divergence minimization.

Parameters: a (ndarray [$$N$$]) – coefficients params (dict) – dictionary of parameters
minimize_kl_divergence_objective(a, params)[source]

Objective function $$\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$ for the KL-divergence minimization.

Parameters: a (ndarray [$$N$$]) – coefficients params (dict) – dictionary of parameters
minimize_kl_divergence_tuple_grad_a_objective(a, params)[source]

Function evaluation and gradient of the objective $$\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$ for the KL-divergence minimization.

Parameters: a (ndarray [$$N$$]) – coefficients params (dict) – dictionary of parameters
n_coeffs

Returns the total number of coefficients.

Returns: total number $$N$$ of coefficients characterizing the transport map.
precomp_evaluate(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ (dict of list [$$d$$] dict) – necessary structures
precomp_grad_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ (dict of list [$$d$$] dict) – necessary structures
precomp_hess_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^2_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ (dict of list [$$d$$] dict) – necessary structures
regression(t, tparams=None, d=None, qtype=None, qparams=None, x=None, w=None, x0=None, regularization=None, tol=0.0001, maxit=100, batch_size_list=None, mpi_pool_list=None)[source]

Compute $${\bf a}^* = \arg\min_{\bf a} \Vert T - T({\bf a}) \Vert_{\pi}$$.

This regression problem can be completely decoupled if the measure is a product measure, obtaining

$a^{(i)*} = \arg\min_{\bf a^{(i)}} \Vert T_i - T_i({\bf a}^{(i)}) \Vert_{\pi_i}$
Parameters: t (function or ndarray [$$m$$]) – function $$t$$ with signature t(x) or its functions values tparams (dict) – parameters for function $$t$$ d (Distribution) – distribution $$\pi$$ qtype (int) – quadrature type to be used for the approximation of $$\mathbb{E}_{\pi}$$ qparams (object) – parameters necessary for the construction of the quadrature x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$ w (ndarray [$$m$$]) – quadrature weights used for the approximation of $$\mathbb{E}_{\pi}$$ x0 (ndarray [$$N$$]) – coefficients to be used as initial values for the optimization regularization (dict) – defines the regularization to be used. If None, no regularization is applied. If key type=='L2' then applies Tikonhov regularization with coefficient in key alpha. tol (float) – tolerance to be used to solve the regression problem. maxit (int) – maximum number of iterations batch_size_list (list [d] tuple  int) – Each of the tuples in the list corresponds to each component of the map. The entries of the tuple define whether to evaluate the regression in batches of a certain size or not. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. (Note: if nprocs > 1, then the batch size defines the size of the batch for each process) mpi_pool_list (list [d] mpi_map.MPI_Pool or None) – pool of processes to be used for function evaluation, gradient evaluation and Hessian evaluation for each component of the approximation. Value None will use serial evaluation. (list [$$d$$]) containing log information from the optimizer.

See also

MonotonicApproximation

Note

the resulting coefficients $${\bf a}$$ are automatically set at the end of the optimization. Use get_coeffs() in order to retrieve them.

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

tuple_grad_a_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute $$\left(\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a}),\nabla_{\bf a}[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert ]\right)$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points pi (Distributions.Distribution) – distribution to be pulled back params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ 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. cache (dict) – cache (tuple) – $$\left(\log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a}),\nabla_{\bf a}[ \log \pi \circ T({\bf x,a}) + \log \vert\det \nabla_{\bf x}T({\bf x,a})\vert ]\right)$$ ValueError – if $$d$$ does not match the dimension of the transport map.
class TransportMaps.Maps.InverseTransportMap(tm)[source]

Given the transport map $$T$$, define $$S=T^{-1}$$.

Parameters: tm (TransportMap) – map $$T$$
coeffs

Returns the actual value of the coefficients.

Returns: (ndarray [$$N$$]) – coefficients.
evaluate(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Evaluate the transport map at the points $${\bf x} \in \mathbb{R}^{m \times d}$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – transformed points ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a(x, *args, **kwargs)[source]

Compute $$\nabla_{\bf a} \hat{S}({\bf x},{\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,N$$]) – $$\nabla_{\bf a} T^{-1}({\bf x},{\bf a})$$ ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_inverse(x, *args, **kwargs)[source]

Compute $$\nabla_{\bf a} \hat{S}^{-1}({\bf x},{\bf a}) = \nabla_{\bf a} T({\bf x},{\bf a})$$

By the definition of the transport map $$T({\bf x},{\bf a})$$, the components $$T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, … are defined by different sets of parameters $${\bf a}^{(1)}$$, $${\bf a}^{(2)}$$, etc.

For this reason $$\nabla_{\bf a} T({\bf x},{\bf a})$$ is block diagonal:

\nabla_a T({\bf x},{\bf a}) = \begin{bmatrix} \left[ \nabla_{{\bf a}^{(1)}} T_1 ({\bf x}_1, {\bf a}^{(1)}) \right]^T & {\bf 0} & \cdots \\ {\bf 0} & \left[ \nabla_{{\bf a}^{(2)}} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)}) \right]^T & \\ \vdots & & \ddots \end{bmatrix}

Consequentely this function will return only the diagonal blocks of the gradient.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (list of ndarray [$$n_i$$]) – list containing $$\nabla_{{\bf a}^{(1)}} T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$\nabla_{{\bf a}^{(2)}} T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, etc. ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x_inverse(x, *args, **kwargs)[source]

Compute $$\nabla_{\bf x} \hat{S}^{-1}({\bf x},{\bf a}) = \nabla_{\bf x} T({\bf x},{\bf a})$$.

This is

\nabla_{\bf x} T({\bf x},{\bf a}) = \begin{bmatrix} \nabla_{\bf x} T_1({\bf x},{\bf a}) \\ \nabla_{\bf x} T_2({\bf x},{\bf a}) \\ \vdots \\ \nabla_{\bf x} T_d({\bf x},{\bf a}) \end{bmatrix}

for every evaluation point.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d$$]) – gradient matrices for every evaluation point. ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_inverse(x, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x} \hat{S}^{-1}({\bf x},{\bf a}) = \nabla^2_{\bf x} T({\bf x},{\bf a})$$.

This is the tensor

$\left[\nabla^2_{\bf x} T({\bf x},{\bf a})\right]_{i,k,:,:} = \nabla^2_{\bf x} T_k({\bf x}^{(i)},{\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
inverse(x, *args, **kwargs)[source]

Compute: $$\hat{S}^{-1}({\bf y},{\bf a})$$

Parameters: y (ndarray [$$m,d$$]) – evaluation points (ndarray [$$m,d$$]) – $$T^{-1}({\bf y},{\bf a})$$ for every evaluation point
n_coeffs

Returns the total number of coefficients.

Returns: total number $$N$$ of coefficients characterizing the transport map.
class TransportMaps.Maps.CompositeTransportMap(*args, **kwargs)[source]
class TransportMaps.Maps.ListCompositeTransportMap(*args, **kwargs)[source]
class TransportMaps.Maps.ListStackedTransportMap(*args, **kwargs)[source]
class TransportMaps.Maps.IdentityTransportMap(dim)[source]

Map $$T({\bf x})={\bf x}$$.

evaluate(x, *args, **kwargs)[source]

[Abstract] Evaluate the map $$T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
hess_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the Hessian $$\nabla^2_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.PermutationTransportMap(p)[source]

Map $$T({\bf x}) = [x_{p(0)}, \ldots, x_{p(d)}]^T$$

Parameters: p (list) – permutation list $$p$$
evaluate(x, *args, **kwargs)[source]

[Abstract] Evaluate the map $$T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
hess_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the Hessian $$\nabla^2_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.LinearTransportMap(constantTerm, linearTerm, log_det=None)[source]

Linear map $$T({\bf x})={\bf c} + {\bf L}{\bf x}$$

Parameters: constantTerm (ndarray [$$d$$]) – term $${\bf c}$$ linearTerm (ndarray [$$d,d$$]) – term $${\bf L}$$ log_det (float) – $$\log\det{\bf L}$$, only required if $${\bf L}$$ is in the sparse format :module:scipy.sparse.
L

The linear term $${\bf L}$$

action_hess_x(x, dx, *args, **kwargs)[source]

Compute $$\langle\nabla^2_{\bf x} \hat{T}({\bf x},{\bf a}), \delta{\bf x}\rangle$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian (ndarray [$$d,d$$]) – action of the Hessian matrix (zero everywhere). ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_x_inverse(x, dx, *args, **kwargs)[source]

Compute $$\langle\nabla^2_{\bf x} \hat{T}^{-1}({\bf x},{\bf a}), \delta{\bf x}\rangle$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian (ndarray [$$d,d$$]) – action of Hessian matrix (zero everywhere). ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_x_log_det_grad_x(x, dx, *args, **kwargs)[source]

Compute: $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}),\delta{\bf x}\rangle$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

action_hess_x_log_pullback(x, pi, dx, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None, *args, **kwargs)[source]

Compute $$\langle \nabla^2_{\bf x}\left[ \log \pi \circ \hat{T}({\bf x,a}) + \log \vert\det \nabla_{\bf x}\hat{T}({\bf x,a})\vert \right], \delta{\bf x}\rangle$$.

Parameters: pi (Distributions.Distribution) – distribution to be pulled back x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ (ndarray [$$m,d,d$$]) – $$\langle\nabla^2_{\bf x}\left[ \log \pi \circ \hat{T}({\bf x,a}) + \log \vert\det \nabla_{\bf x}\hat{T}({\bf x,a})\vert \right], \delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
static build_from_Gaussian(typeMap='Sym')[source]

Build a linear transport map from a standard normal to a Gaussian distribution pi

Parameters: pi (GaussianDistribution) – constant term of the linear map ValueError – if the shape of linear and constant term are inconsistent.
c

The constant term $${\bf c}$$

coeffs

Returns the constant and linear term of the linear map.

Returns: (ndarray, ndarray) – tuple (constant term, linear term)
det_grad_x(x, *args, **kwargs)[source]

Compute: $$\det \nabla_{\bf x} \hat{T}({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (float) – $$\det \nabla_{\bf x} \hat{T}({\bf x}, {\bf a})$$ (constant at every evaluation point) ValueError – if $$d$$ does not match the dimension of the transport map.
evaluate(x, *args, **kwargs)[source]

Evaluate the transport map at the points $${\bf x} \in \mathbb{R}^{m \times d}$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (ndarray [$$m,d$$]) – transformed points ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x(x, *args, **kwargs)[source]

Compute $$\nabla_{\bf x} \hat{T}({\bf x},{\bf a})$$.

\nabla_{\bf x} \hat{T}({\bf x},{\bf a}) = \begin{bmatrix} \nabla_{\bf x} \hat{T}_1({\bf x},{\bf a}) \\ \nabla_{\bf x} \hat{T}_2({\bf x},{\bf a}) \\ \vdots \\ \nabla_{\bf x} \hat{T}_d({\bf x},{\bf a}) \end{bmatrix}

for every evaluation point.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (ndarray [$$d,d$$]) – gradient matrix (constant at every evaluation point). ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x_inverse(x, *args, **kwargs)[source]

Compute $$\nabla_{\bf x} \hat{T}^{-1}({\bf x},{\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (ndarray [$$d,d$$]) – gradient matrix (constant at every evaluation point). ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x_log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_x_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None, *args, **kwargs)[source]

Compute: $$\nabla_{\bf x}\left[ \log \pi \circ \hat{T}({\bf x,a}) + \log \vert\det \nabla_{\bf x}\hat{T}({\bf x,a})\vert \right]$$

Parameters: pi (Distributions.Distribution) – distribution to be pulled back x (ndarray [$$m,d$$]) – evaluation points params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ (ndarray [$$m,d$$]) – $$\nabla_{\bf x}\left[ \log \pi \circ \hat{T}({\bf x,a}) + \log \vert\det \nabla_{\bf x}\hat{T}({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

log_pullback(), grad_x() and grad_x_log_det_grad_x().

hess_x(x, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x} \hat{T}({\bf x},{\bf a})$$.

Args: x (ndarray [$$m,d$$]): evaluation points

Returns: (ndarray [$$d,d,d$$]) – Hessian matrix (zero everywhere).

Raises: ValueError: if $$d$$ does not match the dimension of the transport map.

hess_x_inverse(x, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x} \hat{T}^{-1}({\bf x},{\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (ndarray [$$d,d,d$$]) – Hessian matrix (zero everywhere). ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values (ndarray [$$m,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

hess_x_log_pullback(x, pi, params_t=None, params_pi=None, idxs_slice=slice(None, None, None), cache=None, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x}\left[ \log \pi \circ \hat{T}({\bf x,a}) + \log \vert\det \nabla_{\bf x}\hat{T}({\bf x,a})\vert \right]$$.

Parameters: pi (Distributions.Distribution) – distribution to be pulled back x (ndarray [$$m,d$$]) – evaluation points params_t (dict) – parameters for the evaluation of $$T_{\bf a}$$ params_pi (dict) – parameters for the evaluation of $$\pi$$ (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x}\left[ \log \pi \circ \hat{T}({\bf x,a}) + \log \vert\det \nabla_{\bf x}\hat{T}({\bf x,a})\vert \right]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
inverse(y, *args, **kwargs)[source]

Compute: $$\hat{T}^{-1}({\bf y},{\bf a})$$

Parameters: y (ndarray [$$m,d$$]) – evaluation points (ndarray [$$m,d$$]) – $$\hat{T}^{-1}({\bf y},{\bf a})$$ for every evaluation point
log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\log \det \nabla_{\bf x} \hat{T}({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (float) – $$\log \det \nabla_{\bf x} \hat{T}({\bf x}, {\bf a})$$ (constant at every evaluation point) ValueError – if $$d$$ does not match the dimension of the transport map.
log_det_grad_x_inverse(x, *args, **kwargs)[source]

Compute: $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points (float) – $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ (constant at every evaluation point)
set_coeffs

Returns the constant and linear term of the linear map.

Returns: (ndarray, ndarray) – tuple (constant term, linear term)
class TransportMaps.Maps.TriangularTransportMap(active_vars, approx_list)[source]

Generalized triangular transport map $$T({\bf x},{\bf a})$$.

For $${\bf x} \in \mathbb{R}^d$$, and parameters $${\bf a} \in \mathbb{R}^N$$, the parametric transport map is given by

T({\bf x},{\bf a}) = \begin{bmatrix} T_1 \left({\bf x}_1, {\bf a}^{(1)}\right) \\ T_2 \left({\bf x}_{1:2}, {\bf a}^{(2)}\right) \\ T_3 \left({\bf x}_{1:3}, {\bf a}^{(3)}\right) \\ \vdots \\ T_d \left({\bf x}_{1:d}, {\bf a}^{(d)}\right) \end{bmatrix}

where $${\bf a}^{(i)} \in \mathbb{R}^{n_i}$$ and $$\sum_{i=1}^d n_ = N$$.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.MonotonicFunctionApproximation) – list of monotonic functional approximations for each dimension
action_hess_a_log_det_grad_x(x, da, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\langle\nabla^2_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf a}\rangle$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points da (ndarray [$$N$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,N$$]) – $$\langle\nabla^2_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf a}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_x_log_det_grad_x(x, dx, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute: $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$N,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
allocate_cache_minimize_kl_divergence(x)[source]

Allocate cache space for the KL-divergence minimization

Parameters: x (ndarray [$$m,d$$]) – evaluation points
det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\det \nabla_{\bf x} T({\bf x}, {\bf a}) = \prod_{k=1}^d \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_hess_x_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute: $$\nabla_{\bf a}\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – $$\nabla_{\bf a}\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_inverse(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla_{\bf a} T^{-1}({\bf x},{\bf a})$$

By the definition of the transport map $$T({\bf x},{\bf a})$$, the components $$T_1 ({\bf x}_1, {\bf a}^{(1)})$$, $$T_2 ({\bf x}_{1:2}, {\bf a}^{(2)})$$, … are defined by different sets of parameters $${\bf a}^{(1)}$$, $${\bf a}^{(2)}$$, etc.

Differently from grad_a(), $$\nabla_{\bf a} T^{-1}({\bf x},{\bf a})$$ is not block diagonal, but only lower block triangular Consequentely this function will return the full gradient.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,N$$]) – $$\nabla_{\bf a} T^{-1}({\bf x},{\bf a})$$ ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\nabla_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,N$$]) – $$\nabla_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
grad_a_partial_xd(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$[\nabla_{\bf a}\partial_{{\bf x}_k} T_k]_k$$

This is

$\begin{split}\left[ \begin{array}{ccccc} \nabla_{{\bf a}_1}\partial_{{\bf x}_1}T_1 & 0 & \cdots & & 0 \\ 0 \nabla_{{\bf a}_2}\partial_{{\bf x}_2}T_2 & 0 & \cdots & 0 \\ \vdots & \ddots & & & \\ 0 & & \cdots & 0 & \nabla_{{\bf a}_d}\partial_{{\bf x}_d}T_d \end{array} \right]\end{split}$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,d$$]) – $$[\partial_{{\bf x}_1}T_1({\bf x}_1,{\bf a}^{(1)}),\ldots,\partial_{{\bf x}_d}T_d({\bf x}_{1:d},{\bf a}^{(d)})]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x_inverse(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute $$\nabla_{\bf x} T^{-1}({\bf x},{\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – gradient matrices for every evaluation point. NotImplementedError – to be implemented in subclasses
grad_x_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

hess_a_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\nabla^2_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,N,N$$]) – $$\nabla^2_{\bf a} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
inverse(x, precomp=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

Compute: $$T^{-1}({\bf y},{\bf a})$$

If the map has more input than outputs $$d_{\rm in} > d_{\rm out}$$, it consider the first $$d_{\rm in} - d_{\rm out}$$ values in x to be already inverted values and feed them to the following approximations to find the inverse.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$T^{-1}({\bf y},{\bf a})$$ for every evaluation point ValueError – if $$d_{\rm in} < d_{\rm out}$$
log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\log \det \nabla_{\bf x} T({\bf x}, {\bf a}) = \sum_{k=1}^d \log \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
log_det_grad_x_inverse(x, precomp=None, idxs_slice=slice(None, None, None))[source]

Compute: $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\log \det \nabla_{\bf y} T^{-1}({\bf x}, {\bf a}) = \sum_{k=1}^d \log \partial_{{\bf x}_k} T^{-1}_k({\bf y}_{1:k}, {\bf a}^{(k)})$

For $${\bf x} = T^{-1}({\bf y}, {\bf a})$$,

$\log \det \nabla_{\bf y} T^{-1}({\bf x}, {\bf a}) = - \sum_{k=1}^d \log \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
partial_xd(x, precomp=None, idxs_slice=slice(None, None, None), cache=None)[source]

Compute: $$[\partial_{{\bf x}_1}T_1({\bf x}_1,{\bf a}^{(1)}),\ldots,\partial_{{\bf x}_d}T_d({\bf x}_{1:d},{\bf a}^{(d)})]$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,d$$]) – $$[\partial_{{\bf x}_1}T_1({\bf x}_1,{\bf a}^{(1)}),\ldots,\partial_{{\bf x}_d}T_d({\bf x}_{1:d},{\bf a}^{(d)})]$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
precomp_grad_x_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla_{\bf x}\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ (dict of list [$$d$$] dict) – necessary structures
precomp_hess_x_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^2_{\bf x}\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ (dict of list [$$d$$] dict) – necessary structures
precomp_minimize_kl_divergence(x, params, precomp_type='uni')[source]

Precompute necessary structures for the speed up of minimize_kl_divergence()

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points params (dict) – parameters to be updated precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ (tuple (None,:class:dict)) – dictionary of necessary strucutres. The first argument is needed for consistency with
precomp_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ (dict of list [$$d$$] dict) – necessary structures
reset_cache_minimize_kl_divergence(cache)[source]

Reset the cache space for the KL-divergence minimization

Parameters: cache (dict) – dictionary of cached values
class TransportMaps.Maps.MonotonicTriangularTransportMap(active_vars, approx_list)[source]

[Abstract] Triangular transport map which is monotone by construction.

minimize_kl_divergence(d1, d2, qtype=None, qparams=None, x=None, w=None, params_d1=None, params_d2=None, x0=None, regularization=None, tol=0.0001, maxit=100, ders=2, fungrad=False, hessact=False, precomp_type='uni', batch_size=None, mpi_pool=None, grad_check=False, hess_check=False)[source]

Compute: $${\bf a}^* = \arg\min_{\bf a}\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$

Parameters: d1 (Distribution) – distribution $$\pi_1$$ d2 (Distribution) – distribution $$\pi_2$$ qtype (int) – quadrature type number provided by $$\pi$$ qparams (object) – inputs necessary to the generation of the selected quadrature x (ndarray [$$m,d$$]) – quadrature points w (ndarray [$$m$$]) – quadrature weights params_d1 (dict) – parameters for distribution $$\pi_1$$ params_d2 (dict) – parameters for distribution $$\pi_2$$ x0 (ndarray [$$N$$]) – coefficients to be used as initial values for the optimization regularization (dict) – defines the regularization to be used. If None, no regularization is applied. If key type=='L2' then applies Tikonhov regularization with coefficient in key alpha. tol (float) – tolerance to be used to solve the KL-divergence problem. maxit (int) – maximum number of iterations ders (int) – order of derivatives available for the solution of the optimization problem. 0 -> derivative free, 1 -> gradient, 2 -> hessian. fungrad (bool) – whether the target distribution provides the method Distribution.tuple_grad_x_log_pdf() computing the evaluation and the gradient in one step. This is used only for ders==1. hessact (bool) – use the action of the Hessian. The target distribution must implement the function Distribution.action_hess_x_log_pdf(). precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ batch_size (int) – size of the batch to be used for each iteration. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. If the target distribution is a ProductDistribution, then the optimization problem decouples and batch_size is a list of lists containing the batch sizes to be used for each component of the map. mpi_pool (mpi_map.MPI_Pool or list of mpi_pool) – pool of processes to be used, None stands for one process. If the target distribution is a ProductDistribution, then the minimization problem decouples and mpi_pool is a list containing mpi_pools for each component of the map. grad_check (bool) – whether to use finite difference to check the correctness of of the gradient hess_check (bool) – whether to use finite difference to check the correctenss of the Hessian log informations from the solver log (dict)

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

minimize_kl_divergence_complete(d1, d2, x=None, w=None, params_d1=None, params_d2=None, x0=None, regularization=None, tol=0.0001, maxit=100, ders=2, fungrad=False, hessact=False, precomp_type='uni', batch_size=None, mpi_pool=None, grad_check=False, hess_check=False)[source]

Computes $${\bf a}^* = \arg\min_{\bf a}\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$ for non-product distributions.

See also

:fun:TriangularTransportMap.minimize_kl_divergence for a description of the parameters

class TransportMaps.Maps.TriangularListStackedTransportMap(tm_list)[source]

Triangular transport map obtained by stacking $$T_1, T_2, \ldots$$.

The maps must be such that $${\rm dim}({\rm range}(T_{i-1})) = {\rm dim}({\rm domain}(T_i))$$.

Parameters: tm_list (list of TransportMap) – list of transport maps $$T_i$$
inverse(x, precomp=None, idxs_slice=slice(None, None, None))[source]

Compute: $$T^{-1}({\bf y},{\bf a})$$

If the map has more input than outputs $$d_{\rm in} > d_{\rm out}$$, it consider the first $$d_{\rm in} - d_{\rm out}$$ values in x to be already inverted values and feed them to the following approximations to find the inverse.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$T^{-1}({\bf y},{\bf a})$$ for every evaluation point ValueError – if $$d_{\rm in} < d_{\rm out}$$
log_det_grad_x(x, precomp=None, idxs_slice=slice(None, None, None))[source]

Compute: $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\log \det \nabla_{\bf x} T({\bf x}, {\bf a}) = \sum_{k=1}^d \log \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
log_det_grad_x_inverse(x, precomp=None, idxs_slice=slice(None, None, None))[source]

Compute: $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
class TransportMaps.Maps.FrozenLinearDiagonalTransportMap(a, b)[source]

Linear diagonal transport map $$(x_1,\ldots,x_d) \rightarrow (a_1+b_1 x_1, \ldots, a_d + b_d x_d)$$

Parameters: a (ndarray [$$d$$]) – coefficients b (ndarray [$$d$$]) – coefficients

Note

This map is frozen, meaning that optimizing the coefficients with respect to a certain cost function is not allowed.

See also

TriangularTransportMap for a description of the overridden methods and FunctionalApproximations.FrozenLinear for a description of the linear approximation used for each component.

action_hess_x(x, dx, *args, **kwargs)[source]

Compute $$\langle\nabla^2_{\bf x} T({\bf x},{\bf a}),\delta{\bf x}\rangle$$.

This is the tensor

$\left[\nabla^2_{\bf x} T({\bf x},{\bf a})\right]_{i,k,:i} = \langle \nabla^2_{\bf x} T_k({\bf x}^{(i)},{\bf a}^{(k)}), \delta{\bf x}\rangle$
Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_x_log_det_grad_x(x, dx, *args, **kwargs)[source]

Compute: $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$N,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
det_grad_x(x, *args, **kwargs)[source]

Compute: $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\det \nabla_{\bf x} T({\bf x}, {\bf a}) = \prod_{k=1}^d \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
evaluate(x, *args, **kwargs)[source]

Evaluate the transport map at the points $${\bf x} \in \mathbb{R}^{m \times d}$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,d$$]) – transformed points ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x(x, *args, **kwargs)[source]

This is a diagonal map

grad_x_log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

hess_x(x, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x} T({\bf x},{\bf a})$$.

This is the tensor

$\left[\nabla^2_{\bf x} T({\bf x},{\bf a})\right]_{i,k,:,:} = \nabla^2_{\bf x} T_k({\bf x}^{(i)},{\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\log \det \nabla_{\bf x} T({\bf x}, {\bf a}) = \sum_{k=1}^d \log \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
n_coeffs

Returns the total number of coefficients.

Returns: total number $$N$$ of coefficients characterizing the transport map.
regression(x, w, F, REG, tol)[source]
Raises: NotImplementedError – this is a frozen transport map.
class TransportMaps.Maps.FrozenExponentialDiagonalTransportMap(dim)[source]

Exponential diagonal transport map $$(x_1,\ldots,x_d) \rightarrow (\exp(x_1), \ldots, \exp(x_d))$$

Parameters: dim (int) – dimension $$d$$ of the transport map

Note

This map is frozen, meaning that optimizing the coefficients with respect to a certain cost function is not allowed.

See also

TriangularTransportMap for a description of the overridden methods and FunctionalApproximations.FrozenExponential for a description of the exponential approximation used for each component.

action_hess_x(x, dx, *args, **kwargs)[source]

Compute $$\langle\nabla^2_{\bf x} T({\bf x},{\bf a}),\delta{\bf x}\rangle$$.

This is the tensor

$\left[\nabla^2_{\bf x} T({\bf x},{\bf a})\right]_{i,k,:i} = \langle \nabla^2_{\bf x} T_k({\bf x}^{(i)},{\bf a}^{(k)}), \delta{\bf x}\rangle$
Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$m,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
action_hess_x_log_det_grad_x(x, dx, *args, **kwargs)[source]

Compute: $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points dx (ndarray [$$N,d$$]) – direction on which to evaluate the Hessian precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\langle\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a}), \delta{\bf x}\rangle$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
det_grad_x(x, *args, **kwargs)[source]

Compute: $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\det \nabla_{\bf x} T({\bf x}, {\bf a}) = \prod_{k=1}^d \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
evaluate(x, *args, **kwargs)[source]

Evaluate the transport map at the points $${\bf x} \in \mathbb{R}^{m \times d}$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m,d$$]) – transformed points ValueError – if $$d$$ does not match the dimension of the transport map.
grad_x(x, *args, **kwargs)[source]

This is a diagonal map

grad_x_inverse(x, *args, **kwargs)[source]

Compute $$\nabla_{\bf x} T^{-1}({\bf x},{\bf a})$$.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – gradient matrices for every evaluation point. NotImplementedError – to be implemented in subclasses
grad_x_log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.

See also

grad_x_log_det_grad_x_inverse(x, *args, **kwargs)[source]

[Abstract] Compute: $$\nabla_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$\nabla_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point

See also

hess_x(x, *args, **kwargs)[source]

Compute $$\nabla^2_{\bf x} T({\bf x},{\bf a})$$.

This is the tensor

$\left[\nabla^2_{\bf x} T({\bf x},{\bf a})\right]_{i,k,:,:} = \nabla^2_{\bf x} T_k({\bf x}^{(i)},{\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d,d$$]) – Hessian matrices for every evaluation point and every dimension. ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
hess_x_log_det_grad_x_inverse(x, *args, **kwargs)[source]

[Abstract] Compute: $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d,d$$]) – $$\nabla^2_{\bf x} \log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$ at every evaluation point
inverse(x, *args, **kwargs)[source]

Compute: $$T^{-1}({\bf y},{\bf a})$$

If the map has more input than outputs $$d_{\rm in} > d_{\rm out}$$, it consider the first $$d_{\rm in} - d_{\rm out}$$ values in x to be already inverted values and feed them to the following approximations to find the inverse.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d$$]) – $$T^{-1}({\bf y},{\bf a})$$ for every evaluation point ValueError – if $$d_{\rm in} < d_{\rm out}$$
log_det_grad_x(x, *args, **kwargs)[source]

Compute: $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\log \det \nabla_{\bf x} T({\bf x}, {\bf a}) = \sum_{k=1}^d \log \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. cache (dict) – cache (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
log_det_grad_x_inverse(x, *args, **kwargs)[source]

Compute: $$\log \det \nabla_{\bf x} T^{-1}({\bf x}, {\bf a})$$.

Since the map is lower triangular,

$\log \det \nabla_{\bf y} T^{-1}({\bf x}, {\bf a}) = \sum_{k=1}^d \log \partial_{{\bf x}_k} T^{-1}_k({\bf y}_{1:k}, {\bf a}^{(k)})$

For $${\bf x} = T^{-1}({\bf y}, {\bf a})$$,

$\log \det \nabla_{\bf y} T^{-1}({\bf x}, {\bf a}) = - \sum_{k=1}^d \log \partial_{{\bf x}_k} T_k({\bf x}_{1:k}, {\bf a}^{(k)})$
Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m$$]) – $$\log \det \nabla_{\bf x} T({\bf x}, {\bf a})$$ at every evaluation point ValueError – if $$d$$ does not match the dimension of the transport map.
n_coeffs

Returns the total number of coefficients.

Returns: total number $$N$$ of coefficients characterizing the transport map.
regression(x, w, F, REG, tol)[source]
Raises: NotImplementedError – this is a frozen transport map.
tuple_grad_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the function and gradient.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (tuple) – function and gradient evaluation NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.FrozenGaussianToUniformDiagonalTransportMap(dim)[source]

Gaussian to Uniform diagonal transport map $$(x_1,\ldots,x_d) \rightarrow (\frac{1}{2}[1+{\rm erf}(x_1/\sqrt{2})], \ldots, \frac{1}{2}[1+{\rm erf}(x_d/\sqrt{2})])$$

Parameters: dim (int) – dimension $$d$$ of the transport map

Note

This map is frozen, meaning that optimizing the coefficients with respect to a certain cost function is not allowed.

See also

TriangularTransportMap for a description of the overridden methods and FunctionalApproximations.FrozenGaussianToUniform for a description of the Gaussian to Uniform approximation used for each component.

n_coeffs

Returns the total number of coefficients.

Returns: total number $$N$$ of coefficients characterizing the transport map.
regression(x, w, F, REG, tol)[source]
Raises: NotImplementedError – this is a frozen transport map.
class TransportMaps.Maps.FrozenBananaMap(a, b)[source]
evaluate(x, *args, **kwargs)[source]

[Abstract] Evaluate the map $$T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y$$]) – transformed points NotImplementedError – to be implemented in sub-classes
grad_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the gradient $$\nabla_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
hess_x(x, *args, **kwargs)[source]

[Abstract] Evaluate the Hessian $$\nabla^2_{\bf x}T$$ at the points $${\bf x} \in \mathbb{R}^{m \times d_x}$$.

Parameters: x (ndarray [$$m,d_x$$]) – evaluation points precomp (dict) – dictionary of precomputed values 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. (ndarray [$$m,d_y,d_x,d_x$$]) – transformed points NotImplementedError – to be implemented in sub-classes
class TransportMaps.Maps.IntegratedExponentialTriangularTransportMap(active_vars, approx_list, full_c_basis_list=None, full_h_basis_list=None)[source]

Triangular transport map where each component is represented by an IntegratedExponential function.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.MonotonicFunctionApproximation) – list of monotonic functional approximations for each dimension full_c_basis_list (list of list) – list of basis for each input of the constant part of each component for a full triangular map (this is needed for some adaptivity algorithm) full_h_basis_list (list of list) – list of basis for each input of the constant part of each component for a full triangular map (this is needed for some adaptivity algorithm)
get_identity_coeffs()[source]

Returns the coefficients corresponding to the identity map

Returns: coefficients (ndarray [$$N$$])
class TransportMaps.Maps.CommonBasisIntegratedExponentialTriangularTransportMap(active_vars, approx_list, full_c_basis_list=None, full_h_basis_list=None)[source]

Triangular transport map $$T$$ where the beases of each component $$T_i$$ are the same for corresponding dimensions.

The advantage of using this class with respect to IntegratedExponentialTriangularTransportMap is that the Vandermonde matrices necessary for the evaluation are shared among every component $$T_i$$.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.LinearSpanApproximation) – list of monotonic functional approximations for each dimension full_c_basis_list (list of list) – list of basis for each input of the constant part of each component for a full triangular map (this is needed for some adaptivity algorithm) full_h_basis_list (list of list) – list of basis for each input of the constant part of each component for a full triangular map (this is needed for some adaptivity algorithm)
minimize_kl_divergence(d1, d2, qtype=None, qparams=None, x=None, w=None, params_d1=None, params_d2=None, x0=None, regularization=None, tol=0.0001, maxit=100, ders=2, fungrad=False, hessact=False, precomp_type='uni', batch_size=[None, None, None], mpi_pool=None, grad_check=False, hess_check=False)[source]

Compute: $${\bf a}^* = \arg\min_{\bf a}\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$

Parameters: d1 (Distribution) – distribution $$\pi_1$$ d2 (Distribution) – distribution $$\pi_2$$ qtype (int) – quadrature type number provided by $$\pi$$ qparams (object) – inputs necessary to the generation of the selected quadrature x (ndarray [$$m,d$$]) – quadrature points w (ndarray [$$m$$]) – quadrature weights params_d1 (dict) – parameters for distribution $$\pi_1$$ params_d2 (dict) – parameters for distribution $$\pi_2$$ x0 (ndarray [$$N$$]) – coefficients to be used as initial values for the optimization regularization (dict) – defines the regularization to be used. If None, no regularization is applied. If key type=='L2' then applies Tikonhov regularization with coefficient in key alpha. tol (float) – tolerance to be used to solve the KL-divergence problem. maxit (int) – maximum number of iterations ders (int) – order of derivatives available for the solution of the optimization problem. 0 -> derivative free, 1 -> gradient, 2 -> hessian. fungrad (bool) – whether the target distribution provides the method Distribution.tuple_grad_x_log_pdf() computing the evaluation and the gradient in one step. This is used only for ders==1. hessact (bool) – use the action of the Hessian. The target distribution must implement the function Distribution.action_hess_x_log_pdf(). precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ batch_size (list [3 or 2] of int) – the list contains the size of the batch to be used for each iteration. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. mpi_pool (mpi_map.MPI_Pool) – pool of processes to be used grad_check (bool) – whether to use finite difference to check the correctness of of the gradient hess_check (bool) – whether to use finite difference to check the correctenss of the Hessian log informations from the solver log (dict)

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

precomp_evaluate(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$T({\bf x},{\bf a})$$

This returns a list of uni-variate Vandermonde matrices with order maximum among the components $$T_i$$.

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_grad_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_grad_x_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla_{\bf x}\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] dict) – necessary structures
precomp_hess_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^2_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_hess_x_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^2_{\bf x}\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] dict) – necessary structures
precomp_nabla3_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^3_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
class TransportMaps.Maps.IntegratedSquaredTriangularTransportMap(active_vars, approx_list, full_c_basis_list=None, full_h_basis_list=None)[source]

Triangular transport map where each component is represented by an IntegratedSquaredLinearSpanApproximation function.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.MonotonicFunctionApproximation) – list of monotonic functional approximations for each dimension full_c_basis_list (list of list) – list of basis for each input of the constant part of each component for a full triangular map (this is needed for some adaptivity algorithm) full_h_basis_list (list of list) – list of basis for each input of the constant part of each component for a full triangular map (this is needed for some adaptivity algorithm)
get_identity_coeffs()[source]

Returns the coefficients corresponding to the identity map

Returns: coefficients (ndarray [$$N$$])
class TransportMaps.Maps.LinearSpanTriangularTransportMap(active_vars, approx_list, full_basis_list=None)[source]

Triangular transport map where each component is represented by an FunctionalApproximations.LinearSpanApproximation function.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.LinearSpanApproximation) – list of functional approximations for each dimension full_basis_list (list of list) – list of basis for each input of each component for a full triangular map (this is needed for some adaptivity algorithm)
class TransportMaps.Maps.CommonBasisLinearSpanTriangularTransportMap(active_vars, approx_list, full_basis_list=None)[source]

Triangular transport map $$T$$ where the beases of each component $$T_i$$ are the same for corresponding dimensions.

The advantage of using this class with respect to LinearSpanTriangularTransportMap is that the Vandermonde matrices necessary for the evaluation are shared among every component $$T_i$$.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.LinearSpanApproximation) – list of functional approximations for each dimension full_basis_list (list of list) – list of basis for each input of each component for a full triangular map (this is needed for some adaptivity algorithm)
precomp_evaluate(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$T({\bf x},{\bf a})$$

This returns a list of uni-variate Vandermonde matrices with order maximum among the components $$T_i$$.

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_grad_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_grad_x_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla_{\bf x}\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] dict) – necessary structures
precomp_hess_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^2_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_hess_x_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^2_{\bf x}\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] dict) – necessary structures
precomp_nabla3_x(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\nabla^3_{\bf x}T({\bf x},{\bf a})$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
precomp_partial_xd(x, precomp=None, precomp_type='uni')[source]

Precompute necessary structures for the evaluation of $$\partial_{x_k}T_k({\bf x},{\bf a})$$ for $$k=1,\ldots,d$$

Enriches the dictionaries in the precomp list if necessary.

Parameters: x (ndarray [$$m,d$$]) – evaluation points precomp (dict) – list of dictionaries of precomputed values precomp_type (str) – only option ‘uni’ is allowed for this TransportMap (dict of list [$$d$$] ndarray) – necessary structures
class TransportMaps.Maps.MonotonicLinearSpanTriangularTransportMap(active_vars, approx_list, full_basis_list=None)[source]

Triangular transport map where each component is represented by an FunctionalApproximations.MonotonicLinearSpanApproximation function.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.MonotonicLinearSpanApproximation) – list of monotonic functional approximations for each dimension full_basis_list (list of list) – list of basis for each input of each component for a full triangular map (this is needed for some adaptivity algorithm)
get_identity_coeffs()[source]

Returns the coefficients corresponding to the identity map

Returns: coefficients (ndarray [$$N$$])
minimize_kl_divergence_complete(d1, d2, x=None, w=None, params_d1=None, params_d2=None, x0=None, regularization=None, tol=0.0001, maxit=100, ders=1, fungrad=False, hessact=False, precomp_type='uni', batch_size=None, mpi_pool=None, grad_check=False, hess_check=False)[source]

Compute: $${\bf a}^* = \arg\min_{\bf a}\mathcal{D}_{KL}\left(\pi_1, \pi_{2,{\bf a}}\right)$$

Parameters: d1 (Distribution) – distribution $$\pi_1$$ d2 (Distribution) – distribution $$\pi_2$$ x (ndarray [$$m,d$$]) – quadrature points w (ndarray [$$m$$]) – quadrature weights params_d1 (dict) – parameters for distribution $$\pi_1$$ params_d2 (dict) – parameters for distribution $$\pi_2$$ x0 (ndarray [$$N$$]) – coefficients to be used as initial values for the optimization regularization (dict) – defines the regularization to be used. If None, no regularization is applied. If key type=='L2' then applies Tikonhov regularization with coefficient in key alpha. tol (float) – tolerance to be used to solve the KL-divergence problem. maxit (int) – maximum number of iterations ders (int) – order of derivatives available for the solution of the optimization problem. 0 -> derivative free (SLSQP), 1 -> gradient (SLSQP). fungrad (bool) – whether the target distribution provides the method Distribution.tuple_grad_x_log_pdf() computing the evaluation and the gradient in one step. This is used only for ders==1. hessact (bool) – this option is disabled for linear span maps (no Hessian used) precomp_type (str) – whether to precompute univariate Vandermonde matrices ‘uni’ or multivariate Vandermonde matrices ‘multi’ batch_size (list  of int) – the list contains the size of the batch to be used for each iteration. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. If the target distribution is a ProductDistribution, then the optimization problem decouples and batch_size is a list of lists containing the batch sizes to be used for each component of the map. mpi_pool (mpi_map.MPI_Pool or list of mpi_pool) – pool of processes to be used, None stands for one process. If the target distribution is a ProductDistribution, then the minimization problem decouples and mpi_pool is a list containing mpi_pools for each component of the map. grad_check (bool) – whether to use finite difference to check the correctness of of the gradient hess_check (bool) – whether to use finite difference to check the correctenss of the Hessian log informations from the solver log (dict)

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

class TransportMaps.Maps.MonotonicCommonBasisLinearSpanTriangularTransportMap(active_vars, approx_list, full_basis_list=None)[source]

Triangular transport map $$T$$ where the beases of each component $$T_i$$ are the same for corresponding dimensions.

The advantage of using this class with respect to LinearSpanTriangularTransportMap is that the Vandermonde matrices necessary for the evaluation are shared among every component $$T_i$$.

Parameters: active_vars (list [$$d$$] of list) – for each dimension lists the active variables. approx_list (list [$$d$$] of FunctionalApproximations.MonotonicLinearSpanApproximation) – list of monotonic functional approximations for each dimension full_basis_list (list of list) – list of basis for each input of each component for a full triangular map (this is needed for some adaptivity algorithm)