CycleComponent#
- class pymc_extras.statespace.models.structural.CycleComponent(name: str | None = None, cycle_length: int | None = None, estimate_cycle_length: bool = False, dampen: bool = False, innovations: bool = True)[source]#
用于建模长期周期性效应的组件
- 参数:
name (str) – 组件的名称。用于生成的坐标和状态名称。如果为 None,将使用描述性名称。
cycle_length (int, 可选) – 周期的长度,以数据的时间单位为准。例如,如果您的数据是月度的,并且您想建模一个 12 个月的周期,请使用
cycle_length=12
。您不能同时指定cycle_length
和estimate_cycle_length
。estimate_cycle_length (bool, 默认 False) – 是否估计周期长度。如果为 True,则模型将添加一个额外的参数
cycle_length
。您不能同时指定cycle_length
和estimate_cycle_length
。dampen (bool, 默认 False) – 是否通过在每个时间步乘以阻尼因子 \(\rho\) 来阻尼周期。如果为 true,则模型将添加一个额外的参数
dampening_factor
。innovations (bool, 默认 True) – 是否在季节性效应的强度中包含随机创新。如果为 True,则模型将添加一个额外的参数
sigma_{name}
。
注释
周期组件在实现上与频域季节性组件非常相似,只是它被限制为 n=1。周期组件可以表示为
\[\begin{split}\begin{align} \gamma_t &= \rho \gamma_{t-1} \cos \lambda + \rho \gamma_{t-1}^\star \sin \lambda + \omega_{t} \\ \gamma_{t}^\star &= -\rho \gamma_{t-1} \sin \lambda + \rho \gamma_{t-1}^\star \cos \lambda + \omega_{t}^\star \\ \lambda &= \frac{2\pi}{s} \end{align}\end{split}\]其中 \(s\) 是
cycle_length
。[1] 建议将此组件用于较长期的周期性效应,例如商业周期,而将季节性组件用于较短期的效应,例如每周或每月的季节性。与 FrequencySeasonality 组件不同,CycleComponent 的长度可以被估计。
示例
估计长度在 6 到 12 年之间的商业周期
from pymc_extras.statespace import structural as st import pymc as pm import pytensor.tensor as pt import pandas as pd import numpy as np data = np.random.normal(size=(100, 1)) # Build the structural model grw = st.LevelTrendComponent(order=1, innovations_order=1) cycle = st.CycleComponent('business_cycle', estimate_cycle_length=True, dampen=False) ss_mod = (grw + cycle).build() # Estimate with PyMC with pm.Model(coords=ss_mod.coords) as model: P0 = pm.Deterministic('P0', pt.eye(ss_mod.k_states), dims=ss_mod.param_dims['P0']) intitial_trend = pm.Normal('initial_trend', dims=ss_mod.param_dims['initial_trend']) sigma_trend = pm.HalfNormal('sigma_trend', dims=ss_mod.param_dims['sigma_trend']) cycle_strength = pm.Normal('business_cycle') cycle_length = pm.Uniform('business_cycle_length', lower=6, upper=12) sigma_cycle = pm.HalfNormal('sigma_business_cycle', sigma=1) ss_mod.build_statespace_graph(data, mode='JAX') idata = pm.sample(nuts_sampler='numpyro')
参考文献
- __init__(name: str | None = None, cycle_length: int | None = None, estimate_cycle_length: bool = False, dampen: bool = False, innovations: bool = True)[source]#
方法
__init__
([name, cycle_length, ...])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
()