简体   繁体   中英

PYMC3 Seasonal Variables

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM