StateSpaceTimeSeries#

class causalpy.pymc_models.StateSpaceTimeSeries[source]#

State-space time series model using pymc_extras.statespace.structural.

Parameters:
  • level_order (int, optional) – Order of the local level/trend component. Defaults to 2.

  • seasonal_length (int, optional) – Seasonal period (e.g., 12 for monthly data with annual seasonality). Defaults to 12.

  • trend_component (optional) – Custom state-space trend component.

  • seasonality_component (optional) – Custom state-space seasonal component.

  • sample_kwargs (dict, optional) – Kwargs passed to pm.sample.

  • mode (str, optional) – Mode passed to build_statespace_graph (e.g., “JAX”).

Methods

StateSpaceTimeSeries.__init__([level_order, ...])

StateSpaceTimeSeries.add_coord(name[, ...])

Register a dimension coordinate with the model.

StateSpaceTimeSeries.add_coords(coords, *[, ...])

Vectorized version of Model.add_coord.

StateSpaceTimeSeries.add_named_variable(var)

Add a random graph variable to the named variables of the model.

StateSpaceTimeSeries.build_model(X, y, coords)

Build the PyMC state-space model. coords must include:

StateSpaceTimeSeries.calculate_cumulative_impact(impact)

StateSpaceTimeSeries.calculate_impact(...)

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.

StateSpaceTimeSeries.copy()

Clone the model.

StateSpaceTimeSeries.create_value_var(...[, ...])

Create a TensorVariable that 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.

StateSpaceTimeSeries.eval_rv_shapes()

Evaluate shapes of untransformed AND transformed free variables.

StateSpaceTimeSeries.fit(X, y, coords)

Fit the model, drawing posterior samples.

StateSpaceTimeSeries.get_context([...])

StateSpaceTimeSeries.initial_point([random_seed])

Compute the initial point of the model.

StateSpaceTimeSeries.logp([vars, jacobian, sum])

Elemwise log-probability of the model.

StateSpaceTimeSeries.logp_dlogp_function([...])

Compile a PyTensor function that computes logp and gradient.

StateSpaceTimeSeries.make_obs_var(rv_var, ...)

Create a TensorVariable for an observed random variable.

StateSpaceTimeSeries.name_for(name)

Check if name has prefix and adds if needed.

StateSpaceTimeSeries.name_of(name)

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[, ...])

Wrapper around forecast: expects coords with 'datetime_index' of future points.

StateSpaceTimeSeries.print_coefficients(labels)

StateSpaceTimeSeries.profile(outs, *[, n, ...])

Compile and profile a PyTensor function which returns outs and takes values of model vars as a dict as an argument.

StateSpaceTimeSeries.register_data_var(data)

Register a data variable with the model.

StateSpaceTimeSeries.register_rv(rv_var, name, *)

Register an (un)observed random variable with the model.

StateSpaceTimeSeries.replace_rvs_by_values(...)

Clone and replace random variables in graphs with their value variables.

StateSpaceTimeSeries.score(X, y, coords)

Compute R^2 between observed and mean forecast.

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.shape_from_dims(dims)

StateSpaceTimeSeries.to_graphviz(*[, ...])

Produce a graphviz Digraph from a PyMC model.

Attributes

basic_RVs

List of random variables the model is defined in terms of.

continuous_value_vars

All the continuous value variables in the model.

coords

Coordinate values for model dimensions.

datalogp

PyTensor scalar of log-probability of the observed variables and potential terms.

dim_lengths

The symbolic lengths of dimensions in the model.

discrete_value_vars

All the discrete value variables in the model.

isroot

observedlogp

PyTensor scalar of log-probability of the observed variables.

parent

potentiallogp

PyTensor scalar of log-probability of the Potential terms.

prefix

root

unobserved_RVs

List of all random variables, including deterministic ones.

unobserved_value_vars

List of all random variables (including untransformed projections), as well as deterministics used as inputs and outputs of the model's log-likelihood graph.

value_vars

List of unobserved random variables used as inputs to the model's log-likelihood (which excludes deterministics).

varlogp

PyTensor scalar of log-probability of the unobserved random variables (excluding deterministic).

varlogp_nojac

PyTensor 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='JAX')[source]#
Parameters:
  • sample_kwargs (Optional[Dict[str, Any]]) – A dictionary of kwargs that get unpacked and passed to the pymc.sample() function. Defaults to an empty dictionary.

  • level_order (int)

  • seasonal_length (int)

  • trend_component (Any | None)

  • seasonality_component (Any | None)

  • mode (str)

classmethod __new__(*args, **kwargs)#