TransportMaps.Distributions.DistributionBase

Module Contents

Classes

Distribution

Abstract distribution \(\nu_\pi\).

class TransportMaps.Distributions.DistributionBase.Distribution(dim)[source]

Bases: TransportMaps.ObjectBase.TMO

Abstract distribution \(\nu_\pi\).

property dim[source]
abstract rvs(m, *args, **kwargs)[source]

[Abstract] Generate \(m\) samples from the distribution.

Parameters:

m (int) – number of samples to generate

Returns:

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

\(d\)-dimensional samples

Raises:

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

abstract quadrature(qtype, qparams, mass, *args, **kwargs)[source]

[Abstract] Generate quadrature points and weights.

Parameters:
  • qtype (int) – quadrature type number. The different types are defined in the associated sub-classes.

  • qparams (object) – inputs necessary to the generation of the selected quadrature

  • mass (float) – total mass of the quadrature (1 for probability measures)

Returns:

(tuple (ndarray [\(m,d\)],

ndarray [\(m\)])) – list of quadrature points and weights

Raises:

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

pdf(x, params=None, idxs_slice=slice(None, None, None), **kwargs)[source]

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

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

  • params (dict) – parameters

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

Returns:

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

at the x points.

Raises:

NotImplementedError – the method calls :fun:`log_pdf`

abstract log_pdf(x, params=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate \(\log \pi({\bf x})\)

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

  • params (dict) – parameters

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

Returns:

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

at the x points.

Raises:

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

abstract grad_x_log_pdf(x, params=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate \(\nabla_{\bf x} \log \pi({\bf x})\)

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

  • params (dict) – parameters

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

Returns:

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

\(\nabla_x\log\pi\) at the x points.

Raises:

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

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

[Abstract] Compute the tuple \(\left(\log \pi({\bf x}), \nabla_{\bf x} \log \pi({\bf x})\right)\)

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

  • params (dict) – parameters

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

  • cache (dict) – cache

Returns:

(tuple) – containing

\(\left(\log \pi({\bf x}), \nabla_{\bf x} \log \pi({\bf x})\right)\)

Raises:

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

abstract hess_x_log_pdf(x, params=None, idxs_slice=slice(None, None, None), *args, **kwargs)[source]

[Abstract] Evaluate \(\nabla^2_{\bf x} \log \pi({\bf x})\)

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

  • params (dict) – parameters

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

Returns:

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

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

Raises:

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

abstract action_hess_x_log_pdf(x, dx, params=None, idxs_slice=slice(None, None, None), **kwargs)[source]

[Abstract] Evaluate \(\langle \nabla^2_{\bf x} \log \pi({\bf x}), \delta{\bf x}\rangle\)

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

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

  • params (dict) – parameters

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

Returns:

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

\(\langle \nabla^2_{\bf x} \log \pi({\bf x}), \delta{\bf x}\rangle\).

Raises:

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

abstract mean_log_pdf()[source]

[Abstract] Evaluate \(\mathbb{E}_{\pi}[\log \pi]\)

Returns:

(float) – \(\mathbb{E}_{\pi}[\log \pi]\)

Raises:

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

test_gradients(x, v=None, method='fd', fd_dx=0.0001, verbose=True)[source]

Automatically tests all the gradients implemented.

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

  • v (ndarray [\(d\)]) – direction on which to evaluate the action of the Hessian

  • method (str) – method to use for testing. Default fd is finite difference

  • fd_dx (float) – finite difference perturbation

Returns:

bool – whether all the implemented gradients pass the test.