TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions

Module Contents

Classes

F_phi

F_sigma

ConstantFunction

Abstract class for functions \(f:\mathbb{R}^d\rightarrow\mathbb{R}\).

IdentityFunction

Abstract class for functions \(f:\mathbb{R}^d\rightarrow\mathbb{R}\).

PriorHyperParameters

Distribution \(\pi(\mu, \sigma, \phi)\)

PriorDynamicsInitialConditions

Conditional distribution \(\pi({\bf X}_{t_0}\vert \mu, \sigma, \phi)\)

PriorDynamicsTransition

Transition distribution \(\pi({\bf X}_{t_{k+1}}\vert {\bf X}_{t_{k}}, \mu, \sigma, \phi)\)

LogLikelihood

Abstract class for log-likelihood \(\log \pi({\bf y}_t \vert {\bf X}_t), \mu, \phi, \sigma\)

StocVolHyperDistribution

Distribution of a Hidden Markov chain model (optionally with hyper-parameters)

Functions

generate_data(nsteps[, mu, sigma, phi])

trim_distribution(old_dens, nsteps)

class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.F_phi(mean, std)[source]

Bases: object

evaluate(x)[source]
grad_x(x)[source]
hess_x(x)[source]
class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.F_sigma(k, theta)[source]

Bases: object

evaluate(x)[source]
grad_x(x)[source]
hess_x(x)[source]
class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.ConstantFunction(constant)[source]

Bases: TransportMaps.Maps.Functionals.Functional

Abstract class for functions \(f:\mathbb{R}^d\rightarrow\mathbb{R}\).

evaluate(x)[source]

[Abstract] Evaluate \(f_{\bf a}\) at x.

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[0].

  • cache (dict) – cache

Returns:

(ndarray [\(m,1\)]) – function evaluations

grad_x(x)[source]

[Abstract] Evaluate \(\nabla_{\bf x} f_{\bf a}\) at x.

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[0].

  • cache (dict) – cache

Returns:

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

\(\nabla_{\bf x} f_{\bf a}({\bf x})\)

hess_x(x)[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[0].

Returns:

(ndarray [\(m,d_y,d_x,d_x\)]) – transformed points

Raises:

NotImplementedError – to be implemented in sub-classes

class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.IdentityFunction[source]

Bases: TransportMaps.Maps.Functionals.Functional

Abstract class for functions \(f:\mathbb{R}^d\rightarrow\mathbb{R}\).

evaluate(x)[source]

[Abstract] Evaluate \(f_{\bf a}\) at x.

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[0].

  • cache (dict) – cache

Returns:

(ndarray [\(m,1\)]) – function evaluations

grad_x(x)[source]

[Abstract] Evaluate \(\nabla_{\bf x} f_{\bf a}\) at x.

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[0].

  • cache (dict) – cache

Returns:

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

\(\nabla_{\bf x} f_{\bf a}({\bf x})\)

hess_x(x)[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[0].

Returns:

(ndarray [\(m,d_y,d_x,d_x\)]) – transformed points

Raises:

NotImplementedError – to be implemented in sub-classes

class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.PriorHyperParameters(is_mu_hyper=False, is_sigma_hyper=False, is_phi_hyper=False, sigma_mu=None)[source]

Bases: TransportMaps.Distributions.FrozenDistributions.NormalDistribution

Distribution \(\pi(\mu, \sigma, \phi)\)

Here \(\mu \sim \mathcal{N}(0,\sigma^2_\mu)\), \(\phi \sim \mathcal{N}(0,1)\) and \(\sigma \sim \mathcal{N}(0,1)\), if they are to be considered hyper-parameters.

Parameters:
  • is_mu_hyper (bool) – whether \(\mu\) is an hyper-parameter

  • is_sigma_hyper (bool) – whether \(\sigma\) is an hyper-parameter

  • is_phi_hyper (bool) – whether \(\phi\) is an hyper-parameter

  • mu_sigma (float) – parameter \(\sigma_\mu\)

class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.PriorDynamicsInitialConditions(is_mu_hyper=False, mu=None, is_sigma_hyper=False, sigma=None, is_phi_hyper=False, phi=None)[source]

Bases: TransportMaps.Distributions.ConditionalDistributionBase.ConditionalDistribution

Conditional distribution \(\pi({\bf X}_{t_0}\vert \mu, \sigma, \phi)\)

Parameters:
  • is_mu_hyper (bool) – whether \(\mu\) is an hyper-parameter

  • is_sigma_hyper (bool) – whether \(\sigma\) is an hyper-parameter

  • is_phi_hyper (bool) – whether \(\phi\) is an hyper-parameter

extract_variables(x)[source]
log_pdf(x, y, cache=None, **kwargs)[source]

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

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

  • y (ndarray [\(m,d_y\)]) – conditioning values \({\bf Y}={\bf y}\)

  • 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

grad_x_log_pdf(x, y, cache=None, **kwargs)[source]

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

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

  • y (ndarray [\(m,d_y\)]) – conditioning values \({\bf Y}={\bf y}\)

  • 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

hess_x_log_pdf(x, y, cache=None, **kwargs)[source]

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

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

  • y (ndarray [\(m,d_y\)]) – conditioning values \({\bf Y}={\bf y}\)

  • 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

class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.PriorDynamicsTransition(is_mu_hyper=False, mu=None, is_sigma_hyper=False, sigma=None, is_phi_hyper=False, phi=None)[source]

Bases: TransportMaps.Distributions.ConditionalDistributionBase.ConditionalDistribution

Transition distribution \(\pi({\bf X}_{t_{k+1}}\vert {\bf X}_{t_{k}}, \mu, \sigma, \phi)\)

Parameters:
  • is_mu_hyper (bool) – whether \(\mu\) is an hyper-parameter

  • is_sigma_hyper (bool) – whether \(\sigma\) is an hyper-parameter

  • is_phi_hyper (bool) – whether \(\phi\) is an hyper-parameter

extract_variables(x)[source]
log_pdf(x, y, cache=None, **kwargs)[source]

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

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

  • y (ndarray [\(m,d_y\)]) – conditioning values \({\bf Y}={\bf y}\)

  • 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

grad_x_log_pdf(x, y, cache=None, **kwargs)[source]

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

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

  • y (ndarray [\(m,d_y\)]) – conditioning values \({\bf Y}={\bf y}\)

  • 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

hess_x_log_pdf(x, y, cache=None, **kwargs)[source]

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

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

  • y (ndarray [\(m,d_y\)]) – conditioning values \({\bf Y}={\bf y}\)

  • 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

class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.LogLikelihood(y, is_mu_hyper=False, is_sigma_hyper=False, is_phi_hyper=False)[source]

Bases: TransportMaps.Likelihoods.LikelihoodBase.LogLikelihood

Abstract class for log-likelihood \(\log \pi({\bf y}_t \vert {\bf X}_t), \mu, \phi, \sigma\)

where, up to integration constants,

\[\log\pi({\bf y}_t \vert {\bf X}_t, \mu, \phi, \sigma) = - \frac{1}{2}({\bf y}_t^2 \exp(-{\bf X}_t))\]
Parameters:
  • y (ndarray) – data

  • is_mu_hyper (bool) – whether \(\mu\) is an hyper-parameter

  • is_phi_hyper (bool) – whether \(\phi\) is an hyper-parameter

  • is_sigma_hyper (bool) – whether \(\sigma\) is an hyper-parameter

extract_variables(x)[source]
evaluate(x, cache=None, **kwargs)[source]

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

Parameters:

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

Returns:

(ndarray [\(m,1\)]) – function evaluations

grad_x(x, cache=None, **kwargs)[source]

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

Parameters:

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

Returns:

(ndarray [\(m,1,d\)]) – gradient evaluations

hess_x(x, cache=None, **kwargs)[source]

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

Parameters:

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

Returns:

(ndarray [\(m,1,d,d\)]) – Hessian evaluations

class TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.StocVolHyperDistribution(is_mu_hyper=False, is_sigma_hyper=False, is_phi_hyper=False, mu=None, sigma=None, phi=None, mu_sigma=1.0, sigma_k=1.0, sigma_theta=0.1, phi_mean=3.0, phi_std=1.0)[source]

Bases: TransportMaps.Distributions.Decomposable.SequentialInferenceDistributions.HiddenMarkovChainDistribution

Distribution of a Hidden Markov chain model (optionally with hyper-parameters)

For the index sets \(A=[t_0,\ldots,t_k]\) with \(t_0<t_1<\ldots <t_k\), \(B \subseteq A\), the user defined transition densities (Distribution) \(\{\pi({\bf Z}_{t_0}\vert\Theta), \pi({\bf Z}_{1}\vert{\bf Z}_{t_{0}},\Theta), \ldots \}\), the prior \(\pi(\Theta)\) and the log-likelihoods (LogLikelihood) \(\{\log\mathcal{L}({\bf y}_t \vert{\bf Z}_t,\Theta)\}_{t\in B}\), defines the distribution

\[\pi(\Theta, {\bf Z}_A \vert {\bf y}_B) = \left( \prod_{t\in B} \mathcal{L}(t; {\bf y}_t \vert {\bf Z}_t, \Theta) \right) \pi({\bf Z}_{t_0},\ldots,{\bf Z}_{t_k},\Theta)\]

associated to the process \({\bf Z}_A\), where \(\pi({\bf Z}_{t_0},\ldots,{\bf Z}_{t_k},\Theta)\) is Markov chain distribution.

Note

Each of the log-likelihoods already embed its own data \({\bf y}_t\). The list of log-likelihoods must be of the same length of the list of transitions. Missing data are simulated by setting the corresponding entry in the list of log-likelihood to None.

Parameters:
  • pi_markov (MarkovChainDistribution) – Markov chain distribution describing \(\pi({\bf Z}_{t_0},\ldots,{\bf Z}_{t_k},\Theta)\)

  • ll_list (list of LogLikelihood) – list of log-likelihoods \(\{\log\mathcal{L}({\bf y}_t \vert {\bf Z}_t,\Theta)\}_{t\in B}\)

property index_mu[source]
property index_sigma[source]
property index_phi[source]
action_hess_x_log_pdf(x, dx, cache=None, **kwargs)[source]

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

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

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

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

  • cache (dict) – cache

Returns:

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

\(\langle\nabla^2_{\bf x} \log \pi({\bf x}\vert{\bf y}), \delta{\bf x}\rangle\) at the x points.

get_tvec()[source]
get_nsteps()[source]
assimilate(y=None, Xt=None)[source]

Assimilate one piece of data.

Parameters:
  • y (ndarray) – data. y==None stands for missing data.

  • Xt (ndarray) – true dynamics

TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.generate_data(nsteps, mu=None, sigma=None, phi=None)[source]
TransportMaps.Distributions.Examples.StochasticVolatility.StocVolHyperDistributions.trim_distribution(old_dens, nsteps)[source]