本文介绍了PYMC3季节变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PYMC3相对较新,我正在尝试实现没有回归变量的贝叶斯结构时间序列(BSTS),例如模型拟合此处.模型如下:

I'm relatively new to PYMC3 and I'm trying to implement a Bayesian Structure Time Series (BSTS) without regressors, for instance the model fit here in R. The model is as follows:

我可以使用GaussianRandomWalk来实现局部线性趋势,如下所示:

I can implement the local linear trend using a GaussianRandomWalk as follows:

delta = pymc3.GaussianRandomWalk('delta',mu=0,sd=1,shape=99)
mu = pymc3.GaussianRandomWalk('mu',mu=delta,sd=1,shape=100)

但是,我不知道如何在PYMC3中编码季节性变量(tau).我是否需要参加自定义的随机游走课程,还是有其他技巧?

However, I'm at a loss for how to encode the seasonal variable (tau) in PYMC3. Do I need to roll a custom random walk class or is there some other trick?

推荐答案

您可以使用

w = pm.Normal('w', sd=sigma_tau, shape=S)
tau = w - tt.concatenate([[0.], w.cumsum()[:-1]])

根据数据,将cumsum用于其他随机游动可能也会更快,这通常避免了后验的相关性,这使采样器的工作更加轻松.

Depending on the data it might also be faster to use cumsum for the other random walks, that often avoids correlations in the posterior, which makes life easier for the sampler.

这篇关于PYMC3季节变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:23