superstats.transition.stochastic#

Transition models for latent time-varying parameters.

class superstats.transition.stochastic.AutoRegression(bounds=None, initial_prior=None, sigma=None, phi=None, delta=None)[source]#

Bases: StochasticTransition

AR(1) autoregressive transition.

Parameters:
boundstuple or None, optional, default: None

Lower and upper bounds for the latent state.

initial_priorPrior or None, optional, default: None

Prior for the initial latent state.

sigmafloat or Prior or None, optional, default: None

Standard deviation of the noise.

phifloat or Prior or None, optional, default: None

Autoregressive coefficient.

deltafloat or Prior, optional, default: 0.0

Additive drift term.

Parameters:

Notes

Implements an AR(1): x_t = phi * x_{t-1} + delta + sigma * eps_t.

sample(batch_size, num_steps)[source]#

Draw batch_size AR(1) trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory.

Returns:
resultdict - dictionary with keys local_params,

hyper_params, and fixed_params

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

sample_one_step(x, params)[source]#

Advance a single AR(1) step.

Parameters:
xfloat

Previous latent state.

paramsdict

Expected keys: sigma, phi, delta.

Returns:
x_nextfloat - the next latent state
Parameters:
Return type:

float

class superstats.transition.stochastic.GaussianProcess(kernel='rbf', kernel_params=None, bounds=None, initial_prior=None)[source]#

Bases: StochasticTransition

Gaussian process transition model.

Draws each trajectory as a GP sample with mean start (from initial_prior) and covariance from kernel, then squashes the result into bounds via a scaled sigmoid.

Parameters:
kernel{“rbf”, “linear”} or Kernel, default “rbf”

Kernel used to build the covariance matrix. Either a registered name or a Kernel instance, including composites built via +/* (e.g. RBFKernel(name=”trend”) + RBFKernel(name=”local”)).

kernel_paramsdict, optional

Maps kernel hyperparameter names (see kernel.hyperparam_names, e.g. “length_scale”, “amplitude” for the default RBF kernel) to a Prior (sampled per-batch) or a fixed float. Any name not given here falls back to DEFAULT_HYPER_PRIORS, same as RandomWalk’s sigma/delta. Combining two kernels of the same type requires an explicit name= on each (see Kernel), which prefixes their hyperparameter names accordingly.

boundstuple or None, optional, default: None

Lower and upper bounds for the latent state.

initial_priorPrior or None, optional, default: None

Prior for the initial latent state.

Parameters:
  • kernel (Literal['rbf', 'linear', 'periodic'] | ~superstats.transition.stochastic.kernel.kernel.Kernel)

  • kernel_params (Dict[str, Prior | float | int | None] | None)

  • bounds (Sequence[float] | None)

  • initial_prior (Prior | None)

Notes

The sample method returns a dict with keys local_params, hyper_params and fixed_params, matching RandomWalk.

sample(batch_size, num_steps)[source]#

Draw batch_size Gaussian process trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory.

Returns:
resultdict - dictionary with keys local_params,

hyper_params, and fixed_params

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

class superstats.transition.stochastic.Jump(bounds=None, initial_prior=None, p_jump=1.0, proposal_prior=None)[source]#

Bases: StochasticTransition

Simple jump process: stay or jump to a proposal draw.

Parameters:
boundstuple or None, optional, default: None

Lower and upper bounds for the latent state.

initial_priorPrior or None, optional, default: None

Prior for the initial latent state.

p_jumpfloat or Prior, optional, default: 1.0

Probability of jumping at each step (or a Prior to infer per-batch).

proposal_priorPrior or None, optional, default: None

Prior from which to draw proposal values when a jump occurs. Falls back to a standard normal Prior if not provided.

Parameters:

Notes

At each step the process either stays at the previous value or jumps to an independent proposal sampled from proposal_prior.

sample(batch_size, num_steps)[source]#

Draw batch_size jump-process trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory.

Returns:
resultdict - dictionary with keys local_params,

hyper_params, and fixed_params

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

sample_one_step(x, params)[source]#

Take one step of the jump process.

Parameters:
xfloat

Previous latent state.

paramsdict

Expected key: p_jump.

Returns:
x_nextfloat - the next latent state
Parameters:
Return type:

float

class superstats.transition.stochastic.LevyFlight(bounds=None, initial_prior=None, sigma=None, delta=None, alpha=None, beta=None)[source]#

Bases: StochasticTransition

Lévy-flight transition with alpha-stable noise and optional drift.

Like a random walk, but the Gaussian increments are replaced with alpha-stable increments, introducing a stability index alpha that controls tail heaviness. alpha=2 recovers Gaussian-like behavior; smaller alpha produces heavy-tailed jumps.

Parameters:
boundstuple or None, optional, default: None

Lower and upper bounds for the latent state.

initial_priorPrior or None, optional, default: None

Prior for the initial latent state.

sigmafloat or Prior or None, optional, default: None

Scale of the alpha-stable increments.

deltafloat or Prior or None, optional, default: None

Additive drift term.

alphafloat or Prior or None, optional, default: None

Stability index in (0, 2] controlling tail heaviness.

betafloat or Prior or None, optional, default: None

Skewness in [-1, 1]. Defaults to 0 (symmetric) if left unset.

Parameters:

Notes

The sample method returns a dict with keys local_params, hyper_params and fixed_params. Use sample_one_step to advance a single time-step given numeric params.

sample(batch_size, num_steps)[source]#

Draw batch_size Lévy-flight trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory.

Returns:
resultdict - dictionary with keys local_params,

hyper_params, and fixed_params

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

sample_one_step(x, params)[source]#

Advance a single step of the Lévy flight.

Parameters:
xfloat

Previous latent state.

paramsdict

Expected keys: sigma, delta, alpha, beta.

Returns:
x_nextfloat - the next latent state
Parameters:
Return type:

float

class superstats.transition.stochastic.Mixture(transitions, mixture_weights=None, bounds=None, initial_prior=None, names=None)[source]#

Bases: StochasticTransition

Mixture over multiple transitions, switching regimes at each step.

Parameters:
transitionssequence of Transition

The component transitions to mix between. Must contain at least two. Each transition must not define its own bounds or initial_prior (these are shared with the mixture instead); a Jump component must use p_jump=1 since mixture weights already define the jump probability.

mixture_weightsPrior or tuple of float or None, optional, default: None

Fixed simplex weights, a dirichlet Prior to infer them per batch, or None for uniform weights over the components.

boundstuple or None, optional, default: None

Lower and upper bounds for the latent state, shared across all component transitions.

initial_priorPrior or None, optional, default: None

Prior for the initial latent state, shared across all component transitions. Required at sample time.

namessequence of str or None, optional, default: None

Names for each component, used to prefix hyperparameter keys. Defaults to each component’s transition_name.

Raises:
ValueError

If fewer than two transitions are given, if any transition defines its own bounds or initial_prior, if a Jump component defines p_jump, if names doesn’t match the number of transitions, or if mixture_weights is a list/tuple with the wrong length or negative values.

TypeError

If mixture_weights is a scalar, or not one of tuple/list/Prior/None.

Parameters:
sample(batch_size, num_steps)[source]#

Draw batch_size mixture trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory.

Returns:
resultdict - dictionary with keys local_params, regimes,

hyper_params, and fixed_params

Raises:
ValueError

If initial_prior was not specified in Mixture(…).

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

class superstats.transition.stochastic.OrnsteinUhlenbeck(bounds=None, initial_prior=None, sigma=None, mu=None, theta=None)[source]#

Bases: StochasticTransition

Ornstein-Uhlenbeck mean-reverting transition.

Parameters:
boundstuple or None, optional, default: None

Lower and upper bounds for the latent state.

initial_priorPrior or None, optional, default: None

Prior for the initial latent state.

sigmafloat or Prior or None, optional, default: None

Diffusion scale.

mufloat or Prior or None, optional, default: None

Long-run mean to revert towards.

thetafloat or Prior or None, optional, default: None

Mean-reversion speed.

Parameters:

Notes

Implements an OU process: x_t = x_{t-1} + theta * (mu - x_{t-1}) + sigma * eps_t.

sample(batch_size, num_steps)[source]#

Draw batch_size Ornstein-Uhlenbeck trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory.

Returns:
resultdict - dictionary with keys local_params,

hyper_params, and fixed_params

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

sample_one_step(x, params)[source]#

Advance a single OU step.

Parameters:
xfloat

Previous latent state.

paramsdict

Expected keys: mu, theta, sigma.

Returns:
x_nextfloat - the next latent state
Parameters:
Return type:

float

class superstats.transition.stochastic.RandomWalk(bounds=None, initial_prior=None, sigma=None, delta=None)[source]#

Bases: StochasticTransition

Random walk transition with Gaussian noise and optional drift.

Parameters:
boundstuple or None, optional, default: None

Lower and upper bounds for the latent state.

initial_priorPrior or None, optional, default: None

Prior for the initial latent state.

sigmafloat or Prior or None, optional, default: None

Standard deviation of the Gaussian increments.

deltafloat or Prior, optional, default: 0.0

Additive drift term.

Parameters:

Notes

The sample method returns a dict with keys local_params, hyper_params and fixed_params. Use sample_one_step to advance a single time-step given numeric params.

sample(batch_size, num_steps)[source]#

Draw batch_size random-walk trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory.

Returns:
resultdict - dictionary with keys local_params,

hyper_params, and fixed_params

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

sample_one_step(x, params)[source]#

Advance a single step of the random walk.

Parameters:
xfloat

Previous latent state.

paramsdict

Expected keys: sigma, delta.

Returns:
x_nextfloat - the next latent state
Parameters:
Return type:

float

class superstats.transition.stochastic.StochasticTransition(bounds=None, initial_prior=None)[source]#

Bases: ABC

Base class for stochastic transition models.

Subclasses implement deterministic dynamics for a single scalar latent parameter. Subclasses must implement sample to generate complete trajectories from resolved parameter values.

Parameters:
boundstuple or np.ndarray or None, optional, default: None

Lower and upper bounds for the latent state, applied via scaled_sigmoid. Falls back to DEFAULT_BOUNDS if not provided.

initial_priorPrior or None, optional, default: None

Prior used to draw initial latent states. Falls back to DEFAULT_INITIAL_PRIOR if not provided.

Attributes:
boundsnp.ndarray

Resolved lower and upper bounds for the latent state.

initial_priorPrior

Resolved prior used to draw initial latent states.

hyper_specsdict

Mapping from hyperparameter names to either a Prior (to be sampled per-batch) or a scalar fixed value. Populated by subclasses.

transition_namestr

Short model name, such as "rw" or "ar1".

Parameters:
dtype#

alias of float32

abstract sample(batch_size, num_steps)[source]#

Generate batch_size latent trajectories of length num_steps.

Parameters:
batch_sizeint

Number of independent trajectories to draw.

num_stepsint

Number of time steps per trajectory (including initial state).

Returns:
resultdict - dictionary with at least keys local_params

(ndarray of shape (batch_size, steps)), hyper_params, and fixed_params describing sampled and fixed hyperparameters

Parameters:
  • batch_size (int)

  • num_steps (int)

Return type:

Dict[str, Any]

Modules

auto_regression

Autoregressive transition models.

gaussian_process

Gaussian-process transition models.

jump

Jump-process transition models.

kernel

Kernel implementations for Gaussian-process transitions.

levy_flight

Lévy-flight transition models.

mixture

Mixture transition models.

ornstein_uhlenbeck

Ornstein-Uhlenbeck transition models.

random_walk

Random-walk transition model.

stochastic_transition

Base stochastic transition interface.