PYMC3 Seasonal Variables

ぐ巨炮叔叔 提交于 2019-12-07 03:04:01

问题


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:

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)

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?


回答1:


You can use

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

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.



来源:https://stackoverflow.com/questions/45806799/pymc3-seasonal-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!