superstats.transition#
Transition models for latent time-varying parameters.
- class superstats.transition.AutoRegression(bounds=None, initial_prior=None, sigma=None, phi=None, delta=None)[source]#
Bases:
StochasticTransitionAR(1) autoregressive transition.
- Parameters:
- bounds
tupleorNone,optional, default:None Lower and upper bounds for the latent state.
- initial_prior
PriororNone,optional, default:None Prior for the initial latent state.
- sigma
floatorPriororNone,optional, default:None Standard deviation of the noise.
- phi
floatorPriororNone,optional, default:None Autoregressive coefficient.
- delta
floatorPrior,optional, default: 0.0 Additive drift term.
- bounds
- Parameters:
Notes
Implements an AR(1): x_t = phi * x_{t-1} + delta + sigma * eps_t.
- class superstats.transition.DeterministicTransition(bounds=None, initial_prior=None)[source]#
Bases:
ABCBase class for deterministic 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:
- bounds
tupleornp.ndarrayorNone,optional, default:None Lower and upper bounds for the latent state, applied via scaled_sigmoid. Falls back to DEFAULT_BOUNDS if not provided.
- initial_prior
PriororNone,optional, default:None Prior used to draw the initial latent state. Falls back to DEFAULT_INITIAL_PRIOR if not provided.
- bounds
- Attributes:
- bounds
np.ndarray Resolved lower and upper bounds for the latent state.
- initial_prior
Prior Resolved prior used to draw initial latent states.
- hyper_specs
dict Mapping from parameter names to either a Prior (sampled per batch), a scalar fixed value, or None to use a deterministic default. Subclasses populate this mapping.
- transition_name
str Short model name, such as
"linear".
- bounds
- Parameters:
- dtype#
alias of
float32
- abstract sample(batch_size, num_steps)[source]#
Generate batch_size latent trajectories of length num_steps.
- Parameters:
- Returns:
- result
dict-dictionarywithkeysdeterministic_params, hyper_params, and fixed_params. deterministic_params is an ndarray of shape (batch_size, steps).
- result
- Parameters:
- Return type:
- sample_from_parameters(params, batch_size, num_steps)[source]#
Generate trajectories from already-resolved transition parameters.
Subclasses used with posterior predictive resimulation should override this method.
paramscontains the subclass’s own hyperparameter names, independent of any name used by aJointPrior.
- class superstats.transition.GaussianProcess(kernel='rbf', kernel_params=None, bounds=None, initial_prior=None)[source]#
Bases:
StochasticTransitionGaussian 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”}
orKernel,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_params
dict,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.
- bounds
tupleorNone,optional, default:None Lower and upper bounds for the latent state.
- initial_prior
PriororNone,optional, default:None Prior for the initial latent state.
- kernel{“rbf”, “linear”}
- Parameters:
Notes
The sample method returns a dict with keys local_params, hyper_params and fixed_params, matching RandomWalk.
- class superstats.transition.Jump(bounds=None, initial_prior=None, p_jump=1.0, proposal_prior=None)[source]#
Bases:
StochasticTransitionSimple jump process: stay or jump to a proposal draw.
- Parameters:
- bounds
tupleorNone,optional, default:None Lower and upper bounds for the latent state.
- initial_prior
PriororNone,optional, default:None Prior for the initial latent state.
- p_jump
floatorPrior,optional, default: 1.0 Probability of jumping at each step (or a Prior to infer per-batch).
- proposal_prior
PriororNone,optional, default:None Prior from which to draw proposal values when a jump occurs. Falls back to a standard normal Prior if not provided.
- bounds
- Parameters:
Notes
At each step the process either stays at the previous value or jumps to an independent proposal sampled from proposal_prior.
- class superstats.transition.LevyFlight(bounds=None, initial_prior=None, sigma=None, delta=None, alpha=None, beta=None)[source]#
Bases:
StochasticTransitionLé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:
- bounds
tupleorNone,optional, default:None Lower and upper bounds for the latent state.
- initial_prior
PriororNone,optional, default:None Prior for the initial latent state.
- sigma
floatorPriororNone,optional, default:None Scale of the alpha-stable increments.
- delta
floatorPriororNone,optional, default:None Additive drift term.
- alpha
floatorPriororNone,optional, default:None Stability index in (0, 2] controlling tail heaviness.
- beta
floatorPriororNone,optional, default:None Skewness in [-1, 1]. Defaults to 0 (symmetric) if left unset.
- bounds
- 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.
- class superstats.transition.Linear(bounds=None, intercept=None, beta=None, normalize_steps=True)[source]#
Bases:
DeterministicTransitionDeterministic linear transition with an intercept and slope.
- Parameters:
- boundssequence
oftwofloatsorNone,optional, default:None Lower and upper bounds for the deterministic trajectory. Tuples and lists are accepted.
- intercept
float,Prior,orNone,optional, default:None Starting value of the trajectory. A Prior samples one intercept per trajectory; None uses the deterministic default prior.
- beta
float,Prior,orNone,optional, default:None Change across the trajectory when normalize_steps=True. A Prior samples one slope per trajectory; None uses the deterministic default prior.
- normalize_stepsbool,
optional, default:True If True, use a time axis from 0 to 1. If False, use integer step indices, so the slope is applied at every step.
- boundssequence
- Parameters:
Notes
The sample method returns a dict with keys deterministic_params, hyper_params, and fixed_params. Trajectory values are clipped to bounds.
- sample_from_parameters(params, batch_size, num_steps)[source]#
Generate trajectories from already-resolved transition parameters.
Subclasses used with posterior predictive resimulation should override this method.
paramscontains the subclass’s own hyperparameter names, independent of any name used by aJointPrior.
- class superstats.transition.Mixture(transitions, mixture_weights=None, bounds=None, initial_prior=None, names=None)[source]#
Bases:
StochasticTransitionMixture over multiple transitions, switching regimes at each step.
- Parameters:
- transitionssequence
ofTransition 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_weights
PriorortupleoffloatorNone,optional, default:None Fixed simplex weights, a dirichlet Prior to infer them per batch, or None for uniform weights over the components.
- bounds
tupleorNone,optional, default:None Lower and upper bounds for the latent state, shared across all component transitions.
- initial_prior
PriororNone,optional, default:None Prior for the initial latent state, shared across all component transitions. Required at sample time.
- namessequence
ofstrorNone,optional, default:None Names for each component, used to prefix hyperparameter keys. Defaults to each component’s transition_name.
- transitionssequence
- Raises:
ValueErrorIf 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.
TypeErrorIf 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:
- Returns:
- result
dict-dictionarywithkeyslocal_params, regimes, hyper_params, and fixed_params
- result
- Raises:
ValueErrorIf initial_prior was not specified in Mixture(…).
- Parameters:
- Return type:
- class superstats.transition.OrnsteinUhlenbeck(bounds=None, initial_prior=None, sigma=None, mu=None, theta=None)[source]#
Bases:
StochasticTransitionOrnstein-Uhlenbeck mean-reverting transition.
- Parameters:
- bounds
tupleorNone,optional, default:None Lower and upper bounds for the latent state.
- initial_prior
PriororNone,optional, default:None Prior for the initial latent state.
- sigma
floatorPriororNone,optional, default:None Diffusion scale.
- mu
floatorPriororNone,optional, default:None Long-run mean to revert towards.
- theta
floatorPriororNone,optional, default:None Mean-reversion speed.
- bounds
- Parameters:
Notes
Implements an OU process: x_t = x_{t-1} + theta * (mu - x_{t-1}) + sigma * eps_t.
- class superstats.transition.Polynomial(bounds=None, intercept=None, betas=None, degree=2, normalize_steps=True)[source]#
Bases:
DeterministicTransitionDeterministic polynomial transition with an intercept and beta weights.
- Parameters:
- boundssequence
oftwofloatsorNone,optional, default:None Lower and upper bounds for the deterministic trajectory. Tuples and lists are accepted.
- intercept
float,Prior,orNone,optional, default:None Constant term of the polynomial. A Prior samples one intercept per trajectory; None uses the deterministic default prior.
- betas
float,Prior, sequenceoffloat/Prior/None,orNone Polynomial coefficients for the non-constant terms. If a single scalar or Prior is provided, the same specification is used for every beta. If a sequence is provided, it must have length degree and each element is used for the corresponding beta weight.
- degree
int,optional, default: 2 Number of polynomial terms beyond the intercept. For example, degree=1 reproduces a linear model, while the default degree=2 gives a quadratic model.
- normalize_stepsbool,
optional, default:True If True, use a time axis from 0 to 1. If False, use integer step indices, so higher-order terms are evaluated on raw step numbers.
- boundssequence
- Parameters:
Notes
The sample method returns a dict with keys deterministic_params, hyper_params, and fixed_params. Trajectory values are clipped to bounds.
- class superstats.transition.RandomWalk(bounds=None, initial_prior=None, sigma=None, delta=None)[source]#
Bases:
StochasticTransitionRandom walk transition with Gaussian noise and optional drift.
- Parameters:
- bounds
tupleorNone,optional, default:None Lower and upper bounds for the latent state.
- initial_prior
PriororNone,optional, default:None Prior for the initial latent state.
- sigma
floatorPriororNone,optional, default:None Standard deviation of the Gaussian increments.
- delta
floatorPrior,optional, default: 0.0 Additive drift term.
- bounds
- 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.
- class superstats.transition.StochasticTransition(bounds=None, initial_prior=None)[source]#
Bases:
ABCBase 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:
- bounds
tupleornp.ndarrayorNone,optional, default:None Lower and upper bounds for the latent state, applied via scaled_sigmoid. Falls back to DEFAULT_BOUNDS if not provided.
- initial_prior
PriororNone,optional, default:None Prior used to draw initial latent states. Falls back to DEFAULT_INITIAL_PRIOR if not provided.
- bounds
- Attributes:
- bounds
np.ndarray Resolved lower and upper bounds for the latent state.
- initial_prior
Prior Resolved prior used to draw initial latent states.
- hyper_specs
dict Mapping from hyperparameter names to either a Prior (to be sampled per-batch) or a scalar fixed value. Populated by subclasses.
- transition_name
str Short model name, such as
"rw"or"ar1".
- bounds
- Parameters:
- dtype#
alias of
float32
- abstract sample(batch_size, num_steps)[source]#
Generate batch_size latent trajectories of length num_steps.
- Parameters:
- Returns:
- result
dict-dictionarywithatleastkeyslocal_params (ndarray of shape (batch_size, steps)), hyper_params, and fixed_params describing sampled and fixed hyperparameters
- result
- Parameters:
- Return type:
Modules
Deterministic transition models for latent time-varying parameters. |
|
Transition models for latent time-varying parameters. |