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:
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.stochastic.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.stochastic.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.stochastic.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.stochastic.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.stochastic.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.stochastic.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.stochastic.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
Autoregressive transition models. |
|
Gaussian-process transition models. |
|
Jump-process transition models. |
|
Kernel implementations for Gaussian-process transitions. |
|
Lévy-flight transition models. |
|
Mixture transition models. |
|
Ornstein-Uhlenbeck transition models. |
|
Random-walk transition model. |
|
Base stochastic transition interface. |