AutoregressiveComponent#

class pymc_extras.statespace.models.structural.AutoregressiveComponent(order: int = 1, name: str = 'AutoRegressive')[source]#

自回归时间序列组件

参数:

order (intsequence of int) – 如果是整数,则为模型中包含的滞后阶数。如果是序列,则为指示模型中包含哪些滞后阶数的零和一的类数组。

注释

自回归组件可以被认为是将序列相关误差引入模型的一种方法。该过程建模为

\[x_t = \sum_{i=1}^p \rho_i x_{t-i}\]

其中 p,要建模的自回归项的数量,是过程的阶数。默认情况下,模型中包含高达 p 的所有滞后阶数。要禁用滞后阶数,请将零和一的列表传递给 order 参数。例如,order=[1, 1, 0, 1] 将变为

\[x_t = \rho_1 x_{t-1} + \rho_2 x_{t-1} + \rho_4 x_{t-1}\]

系数 \(\rho_3\) 已被约束为零。

警告

此类旨在用作结构时间序列模型中的组件。对于使用 ARIMA 对平稳过程进行建模,请使用 statespace.BayesianSARIMA

示例

将时间序列建模为具有非零均值的 AR(2) 过程

from pymc_extras.statespace import structural as st
import pymc as pm
import pytensor.tensor as pt

trend = st.LevelTrendComponent(order=1, innovations_order=0)
ar = st.AutoregressiveComponent(2)
ss_mod = (trend + ar).build()

with pm.Model(coords=ss_mod.coords) as model:
    P0 = pm.Deterministic('P0', pt.eye(ss_mod.k_states) * 10, dims=ss_mod.param_dims['P0'])
    intitial_trend = pm.Normal('initial_trend', sigma=10, dims=ss_mod.param_dims['initial_trend'])
    ar_params = pm.Normal('ar_params', dims=ss_mod.param_dims['ar_params'])
    sigma_ar = pm.Exponential('sigma_ar', 1, dims=ss_mod.param_dims['sigma_ar'])

    ss_mod.build_statespace_graph(data, mode='JAX')
    idata = pm.sample(nuts_sampler='numpyro')
__init__(order: int = 1, name: str = 'AutoRegressive')[source]#

方法

__init__([order, name])

build([name, filter_type, verbose])

从当前组件构建 StructuralTimeSeries 状态空间模型

make_and_register_data(name, shape[, dtype])

用于创建 pytensor 符号变量并将其注册到 _name_to_data 字典的辅助函数

make_and_register_variable(name, shape[, dtype])

用于创建 pytensor 符号变量并将其注册到 _name_to_variable 字典的辅助函数

make_symbolic_graph()

populate_component_properties()