stsb3.sts

AR1

def __init__(
    self,
    name=None,
    t0=0,
    t1=2,
    size=1,
    alpha=None,
    beta=None,
    scale=None,
):

An autoregressive block of order 1.

The data generating process for this block is

\[ z_t = \alpha_t + \beta_t z_{t-1} + \mathrm{scale}_t w_t, \]

for \(t = t_0,...,t_1\) and \(w_t \sim \text{Normal}(0, 1)\). Here, \(\alpha\) is the dgp for the intercept parameter, \(\beta\) is the dgp for the slope parameter, and \(\mathrm{scale}\) is the dgp for the scale parameter. These processes may be other Blocks, torch.tensors, or pyro.distributions objects, and the interpretation of these parameters will change accordingly.

Args:

See Block for definitions of other parameters.

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

BernoulliNoise

def __init__(
    self,
    dgp,
    data=None,
    name=None,
    t0=0,
    t1=2,
    size=1,
):

A noise block (time series likelihood function) that assumes a Bernoulli observation process.

This observation process is suitable for use with on-off / indicator data.

The likelihood function for this block is

\[ p(x | \mathrm{dgp}) = \prod_{t=t_0}^{t_1} \mathrm{Bernoulli}(x_t | \mathrm{dgp}_t) \]

The \(\mathrm{dgp}\) needs to be constrained to lie in (0, 1) because it is used as the probability of the Bernoulli likelihood. Consider using .invlogit(...) on an unconstrained Block.

Args:

See NoiseBlock for definitions of arguments.

_fit_autoguide

None

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

fit

def fit(self, method="nf_block_ar", method_kwargs=dict(), verbosity=0.01):

Fits a guide (variational posterior) to the model.

Wraps multiple Pyro implementations of variational inference. To minimize noise in the estimation you should follow the Pyro guidelines about marginalizing out discrete latent rvs, etc.

Args:

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

posterior_predictive

def posterior_predictive(
    self,
    nsamples=1,
):

Draws from the posterior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

prior_predictive

def prior_predictive(
    self,
    nsamples=1,
):

Draws from the prior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

sample

def sample(
    self,
    nsamples=100,
    thin=0.1,
    burnin=500,
):

Sample from the model’s posterior using the Pyro implementation of the No-U Turn Sampler

This could take a very long time for long time series. It is recommended to use .fit(...) instead.

Args:

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

CCSDE

def __init__(
    self,
    name=None,
    t0=0,
    t1=2,
    size=1,
    loc=None,
    scale=None,
    dt=None,
    ic=None,
):

A constant-coefficient Euler-Maruyama stochastic differential equation dgp.

The generative model for this process is

\[ z_t = z_{t - 1} + \mathrm{dt}_t \mathrm{loc}_t + \sqrt{\mathrm{dt}_t} \mathrm{scale}_t w_t,\ z_0 = \mathrm{ic}, \]

for \(t = t_0, ..., t_1\). Here, \(\mathrm{loc}\) is the dgp for the location parameter, \(\mathrm{scale}\) is the dgp for the scale parameter, and \(\mathrm{dt}\) is the dgp for the time discretization. These processes may be other Blocks, torch.tensors, or pyro.distributions objects, and the interpretation of \(\mathrm{loc}_t\), \(\mathrm{scale}_t\), and \(\mathrm{dt}_t\) will change accordingly. The initial condition, \(\mathrm{ic}\), can be either a torch.tensor or pyro.distributions object. The term \(w_t\) is a standard normal variate.

Args:

See Block for definitions of other parameters.

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

DiscreteSeasonal

def __init__(
    self,
    name=None,
    t0=0,
    t1=2,
    size=1,
    n_seasons=2,
    seasons=None,
):

A discrete seasonal block that represents the most basic form of discrete seasonality.

The data generating process for this block is

\[ z_t = \theta_{t \mod s},\ s = 1,...,S, \]

where \(S\) is the total number of seasons and \(\theta = (\theta_1,...,\theta_S)\) are the seasonality components. Currently, \(\theta\) can be only a pyro.distributions instance or a torch.Tensor, though that might change in a future release.

Args:

See Block for definitions of other parameters.

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

DiscriminativeGaussianNoise

def __init__(
    self,
    dgp,
    X=None,
    y=None,
    name=None,
    t0=0,
    t1=2,
    size=1,
    scale=None,
):

A discriminative noise block used for dynamic regression.

The observation likelihood is given by

\[ p(x | \mathrm{dgp}, \mathrm{scale}) = \prod_{t=t_0}^{t_1} \mathrm{Normal}(x_t | X_t \mathrm{dgp}_t, \mathrm{scale}_t), \]

where \(X_t \mathrm{dgp}_t\) should be interpreted as a batched dot product, i.e., \(\mathrm{loc}_{it} = \sum_j X_{ijt}\mathrm{dgp}_{jt}\).

Args:

See GaussianNoise for definitions of other parameters

_fit_autoguide

None

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

fit

def fit(self, method="nf_block_ar", method_kwargs=dict(), verbosity=0.01):

Fits a guide (variational posterior) to the model.

Wraps multiple Pyro implementations of variational inference. To minimize noise in the estimation you should follow the Pyro guidelines about marginalizing out discrete latent rvs, etc.

Args:

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

posterior_predictive

def posterior_predictive(
    self,
    nsamples=1,
):

Draws from the posterior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

prior_predictive

def prior_predictive(
    self,
    nsamples=1,
):

Draws from the prior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

sample

def sample(
    self,
    nsamples=100,
    thin=0.1,
    burnin=500,
):

Sample from the model’s posterior using the Pyro implementation of the No-U Turn Sampler

This could take a very long time for long time series. It is recommended to use .fit(...) instead.

Args:

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

GaussianNoise

def __init__(
    self,
    dgp,
    data=None,
    name=None,
    t0=0,
    t1=2,
    size=1,
    scale=None,
):

A noise block (time series likelihood function) that assumes a centered normal observation process.

The likelihood function for this block is

\[ p(x | \mathrm{dgp}, \mathrm{scale}) = \prod_{t=t_0}^{t_1} \mathrm{Normal}(x_t | \mathrm{dgp}_t, \mathrm{scale}_t) \]

Args:

See NoiseBlock for definitions of other parameters

_fit_autoguide

None

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

fit

def fit(self, method="nf_block_ar", method_kwargs=dict(), verbosity=0.01):

Fits a guide (variational posterior) to the model.

Wraps multiple Pyro implementations of variational inference. To minimize noise in the estimation you should follow the Pyro guidelines about marginalizing out discrete latent rvs, etc.

Args:

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

posterior_predictive

def posterior_predictive(
    self,
    nsamples=1,
):

Draws from the posterior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

prior_predictive

def prior_predictive(
    self,
    nsamples=1,
):

Draws from the prior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

sample

def sample(
    self,
    nsamples=100,
    thin=0.1,
    burnin=500,
):

Sample from the model’s posterior using the Pyro implementation of the No-U Turn Sampler

This could take a very long time for long time series. It is recommended to use .fit(...) instead.

Args:

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

GlobalTrend

def __init__(
    self,
    name=None,
    t0=0,
    t1=2,
    size=1,
    alpha=None,
    beta=None,
):

A global (linear) trend dgp.

The generative model for this process is

\[ z_t = \alpha + \beta t, \]

for \(t = t_0, ..., t_1\). Here, \(\alpha\) is the dgp for the intercept parameter and \(\beta\) is the dgp for the slope parameter. These processes may be other Blocks, torch.tensors, or pyro.distributions objects, and the interpretation of \(\alpha\) and \(\beta\) will change accordingly.

Args:

See Block for definitions of other parameters.

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

MA1

def __init__(
    self,
    name=None,
    t0=0,
    t1=2,
    size=1,
    beta=None,
    loc=None,
    scale=None,
):

A moving average block of order 1.

The data generating process for this block is

\[ z_t = \mathrm{loc}_t + \mathrm{scale}_t w_t + \beta_t \mathrm{scale}_{t - 1} w_{t-1}, \]

for \(t = t_0,...,t_1\) and \(w_t \sim \text{Normal}(0, 1)\). Here, \(\mathrm{loc}\) is the dgp for the location parameter, \(\mathrm{scale}\) is the dgp for the scale parameter, and \(\beta\) is the dgp for the FIR filter. These processes may be other Blocks, torch.tensors, or pyro.distributions objects, and the interpretation of these parameters will change accordingly.

NOTE: from the definition of the dgp, \(\mathrm{scale}\) has dimensionality \((N, t_1 - t_0 + 1)\), where the \(+1\) is due to the lagged noise term on the \(t = t_0\) value.

Args:

See Block for definitions of other parameters.

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

PoissonNoise

def __init__(
    self,
    dgp,
    data=None,
    name=None,
    t0=0,
    t1=2,
    size=1,
):

A noise block (time series likelihood function) that assumes a Poisson observation process.

This observation process is suitable for use with count (or other non-negative integer) data that does not exhibit over- or under-dispersion (in practice, if the log ratio of mean to variance of the observed data is not too far away from zero).

The likelihood function for this block is

\[ p(x | \mathrm{dgp}) = \prod_{t=t_0}^{t_1} \mathrm{Poisson}(x_t | \mathrm{dgp}_t) \]

The \(\mathrm{dgp}\) needs to be non-negative because it is used as the rate function of the Poisson likelihood. Consider using .softplus(...) or .exp(...) on an unconstrained Block.

Args:

See NoiseBlock for definitions of arguments.

_fit_autoguide

None

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

fit

def fit(self, method="nf_block_ar", method_kwargs=dict(), verbosity=0.01):

Fits a guide (variational posterior) to the model.

Wraps multiple Pyro implementations of variational inference. To minimize noise in the estimation you should follow the Pyro guidelines about marginalizing out discrete latent rvs, etc.

Args:

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

posterior_predictive

def posterior_predictive(
    self,
    nsamples=1,
):

Draws from the posterior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

prior_predictive

def prior_predictive(
    self,
    nsamples=1,
):

Draws from the prior predictive distribution of the graph with self as the root

Args:

Returns:

samples (torch.tensor)

sample

def sample(
    self,
    nsamples=100,
    thin=0.1,
    burnin=500,
):

Sample from the model’s posterior using the Pyro implementation of the No-U Turn Sampler

This could take a very long time for long time series. It is recommended to use .fit(...) instead.

Args:

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

RandomWalk

def __init__(
    self,
    name=None,
    t0=0,
    t1=2,
    size=1,
    loc=None,
    scale=None,
    ic=None,
):

A (biased) normal random walk dgp.

The generative model for this process is

\[ z_t = z_{t - 1} + \mathrm{loc}_t + \mathrm{scale}_t w_t,\ z_0 = \mathrm{ic}, \]

for \(t = t_0,...,t_1\). Here, \(\mathrm{loc}\) is the dgp for the location parameter and \(\mathrm{scale}\) is the dgp for the scale parameter. These processes may be other Blocks, torch.tensors, or pyro.distributions objects, and the interpretation of \(\mathrm{loc}_t\) or \(\mathrm{scale}_t\) will change accordingly. The initial condition, \(\mathrm{ic}\), can be either a torch.tensor or pyro.distributions object. The term \(w_t\) is a standard normal variate.

Args:

See Block for definitions of other parameters.

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

SmoothSeasonal

def __init__(
    self,
    name=None,
    t0=0,
    t1=2,
    size=1,
    phase=None,
    amplitude=None,
    lengthscale=None,
    cycles=1,
):

A smooth seasonal block.

The generative model for this process is

\[ z_t = \mathrm{amplitude}_t \cos\left(\mathrm{phase}_t + \frac{2\pi\ \mathrm{cycles}\ t}{\mathrm{lengthscale}_t}\right) \]

for \(t = t_0, ..., t_1\). Here, \(\mathrm{amplitude}\) is the dgp for the amplitude, \(\mathrm{phase}\) is the dgp for the phase, and \(\mathrm{lengthscale}\) is the parameter for the lengthscale. These processes may be other Blocks, torch.tensors, or pyro.distributions objects, and the interpretation of these parameters will change accordingly.

This block is experimental and may be removed in a future release.

Args:

See Block for definitions of other parameters.

_maybe_add_blocks

def _maybe_add_blocks(self, *args):

Adds parameters to prec and succ if they subclass Block.

Args:

_maybe_remove_blocks

None

_model

None

_transform

Defines a transform from a string argument.

Currently the following string arguments are supported:

The resulting transform will be added to the transform stack iff it is not already at the top of the stack.

Args:

Returns:

self (stsb.Block)

arctanh

x -> arctanh(x), i.e. x -> 0.5 log ((1 + x) / (1 - x))

clear_cache

Clears the block cache.

This method does not alter the cache mode.

cos

x -> cos x

diff

x -> x[1:] - x[:-1]

Note that this lowers the time dimension from T to T - 1.

exp

x -> exp(x)

floor

x -> x - [[x]], where [[.]] is the fractional part operator

invlogit

x -> 1 / (1 + exp(-x))

log

x -> log x

Block paths must be positive for valid output.

logdiff

x -> log x[1:] - log x[:-1]

Note that this lowers the time dimension from T to T - 1.

logit

x -> log(x / (1 - x))

model

def model(self, *args, **kwargs):

Draws a batch of samples from the block.

Args:

Returns:

prec

Returns the predecessor nodes of self in the (implicit) compute graph

Returns:

_prec (list): list of predecessor nodes

sin

x -> sin x

softplus

x -> log(1 + exp(x))

succ

Returns the successor nodes of self in the (implicit) compute graph

Returns:

_succ (list): list of successor nodes

tanh

x -> tanh(x), i.e. x -> (exp(x) - exp(-x)) / (exp(x) + exp(-x))

forecast

def forecast(dgp, samples, *args, Nt=1, nsamples=1, **kwargs):

Forecasts the root node of the DGP forward in time.

Args:

redefine

def redefine(
    block,
    attribute,
    obj,
):

Redefines an attribute of a block to the passed object

Args:

register_block

def register_block(
    name,
    fn_addr_param,
    model_fn,
):

Registers a new block at runtime

Args: