StateSpaceTimeSeries#
- class causalpy.pymc_models.StateSpaceTimeSeries[source]#
State-space time series model using
pymc-extras.statespace.structural.The model combines a local level/trend component with frequency-domain seasonality. When X is passed to fit, its columns (except the patsy Intercept, which the level absorbs) enter as exogenous regressors through a static-coefficient Regression component, and out-of-sample predictions use the post-period X as the forecast scenario.
- Parameters:
level_order (
int) – Order of the local level/trend component. Defaults to 2.seasonal_length (
int) – Seasonal period (e.g., 12 for monthly data with annual seasonality). Defaults to 12.trend_component (
Any|None) – Custom state-space trend component. Must be a pymc-extras structural component (e.g. pymc_extras.statespace.structural.LevelTrend). Components with non-default names introduce their own parameter names; pass matching entries in priors.seasonality_component (
Any|None) – Custom state-space seasonal component. Same requirements as trend_component.sample_kwargs (
dict[str,Any] |None) – Kwargs passed to pm.sample.mode (
str|None) – Pytensor compile mode used when building the state-space model. Defaults to None.priors (
dict[str,Prior] |None) – Dictionary mapping state-space parameter names topymc_extras.prior.Priorobjects, overriding the defaults in default_priors. The P0 covariance is parameterized through its diagonal under the key “P0_diag”. Dims are resolved from the built state-space model, so priors do not need to declare them.vs_prior_type (
Optional[Literal['spike_and_slab','horseshoe','normal']]) – Variable selection prior for the exogenous regression coefficients. Requires covariates. Takes precedence over a beta_exog entry in priors.vs_hyperparams (
dict[str,Any] |None) – Hyperparameters for the variable selection prior. Seecausalpy.variable_selection_priors.VariableSelectionPrior.
Methods
StateSpaceTimeSeries.add_coord(name[, ...])Register a dimension coordinate with the model.
StateSpaceTimeSeries.add_coords(coords, *[, ...])Vectorized version of
Model.add_coord.Add a random graph variable to the named variables of the model.
StateSpaceTimeSeries.build_model([X, y, coords])Build the PyMC state-space model.
StateSpaceTimeSeries.check_start_vals(start, ...)Check that the logp is defined and finite at the starting point.
StateSpaceTimeSeries.compile_d2logp([vars, ...])Compiled log probability density hessian function.
StateSpaceTimeSeries.compile_dlogp([vars, ...])Compiled log probability density gradient function.
StateSpaceTimeSeries.compile_fn(outs, *[, ...])Compiles a PyTensor function.
StateSpaceTimeSeries.compile_logp([vars, ...])Compiled log probability density function.
Clone the model.
StateSpaceTimeSeries.create_value_var(...[, ...])Create a
TensorVariablethat will be used as the random variable's "value" in log-likelihood graphs.StateSpaceTimeSeries.d2logp([vars, ...])Hessian of the models log-probability w.r.t.
StateSpaceTimeSeries.debug([point, fn, verbose])Debug model function at point.
StateSpaceTimeSeries.dlogp([vars, jacobian])Gradient of the models log-probability w.r.t.
Evaluate shapes of untransformed AND transformed free variables.
StateSpaceTimeSeries.fit([X, y, coords])Fit the model, drawing posterior samples.
StateSpaceTimeSeries.fit_mapping(X, y[, coords])Fit a specialized model that accepts mapping-valued inputs.
Posterior inclusion probabilities of the exogenous regressors.
Shrinkage factors of the exogenous regressors.
StateSpaceTimeSeries.initial_point([random_seed])Compute the initial point of the model.
StateSpaceTimeSeries.logp([vars, jacobian, sum])Elemwise log-probability of the model.
Compile a PyTensor function that computes logp and gradient.
StateSpaceTimeSeries.make_obs_var(rv_var, ...)Create a TensorVariable for an observed random variable.
Check if name has prefix and adds if needed.
Check if name has prefix and deletes if needed.
StateSpaceTimeSeries.point_logps([point, ...])Compute the log probability of point for all random variables in the model.
StateSpaceTimeSeries.predict([X, coords, ...])Predict data given input X.
Print the model coefficients with their labels.
Generate priors dynamically based on the input data.
StateSpaceTimeSeries.profile(outs, *[, n, ...])Compile and profile a PyTensor function which returns
outsand takes values of model vars as a dict as an argument.Register a data variable with the model.
StateSpaceTimeSeries.register_rv(rv_var, name, *)Register an (un)observed random variable with the model.
Clone and replace random variables in graphs with their value variables.
StateSpaceTimeSeries.score([X, y, coords])Score the Bayesian R^2 given inputs X and outputs y.
StateSpaceTimeSeries.set_data(name, values)Change the values of a data variable in the model.
StateSpaceTimeSeries.set_dim(name, new_length)Update a mutable dimension.
StateSpaceTimeSeries.set_initval(rv_var, initval)Set an initial value (strategy) for a random variable.
StateSpaceTimeSeries.table(*[, ...])Create a rich table summarizing the model's variables and their expressions.
StateSpaceTimeSeries.to_graphviz(*[, ...])Produce a graphviz Digraph from a PyMC model.
Attributes
basic_RVsList of random variables the model is defined in terms of.
continuous_value_varsAll the continuous value variables in the model.
coordsCoordinate values for model dimensions.
datalogpPyTensor scalar of log-probability of the observed variables and potential terms.
default_priorsdim_lengthsThe symbolic lengths of dimensions in the model.
discrete_value_varsAll the discrete value variables in the model.
isrootobservedlogpPyTensor scalar of log-probability of the observed variables.
parentpotentiallogpPyTensor scalar of log-probability of the Potential terms.
prefixrootunobserved_RVsList of all random variables, including deterministic ones.
unobserved_value_varsList of all random variables (including untransformed projections), as well as deterministics used as inputs and outputs of the model's log-likelihood graph.
value_varsList of unobserved random variables used as inputs to the model's log-likelihood (which excludes deterministics).
varlogpPyTensor scalar of log-probability of the unobserved random variables (excluding deterministic).
varlogp_nojacPyTensor scalar of log-probability of the unobserved random variables (excluding deterministic) without jacobian term.
- __init__(level_order=2, seasonal_length=12, trend_component=None, seasonality_component=None, sample_kwargs=None, mode=None, priors=None, vs_prior_type=None, vs_hyperparams=None)[source]#
- Parameters:
sample_kwargs (
dict[str,Any] |None) – Dictionary of kwargs that get unpacked and passed to thepymc.sample()function. Defaults to an empty dictionary if None.priors (
dict[str,Prior] |None) – Dictionary of priors for the model. Defaults to None, in which case default priors are used.level_order (int)
seasonal_length (int)
trend_component (Any | None)
seasonality_component (Any | None)
mode (str | None)
vs_prior_type (Literal['spike_and_slab', 'horseshoe', 'normal'] | None)
- classmethod __new__(*args, **kwargs)#