我正在尝试构建具有以下组件的PyMC3模型:
GaussianRandomWalk
。在阅读了很多PyMC3文档之后,我发现具有周期协方差的高斯过程将是对周期元素进行建模的最佳方法。麻烦的是,我似乎无法使整个模型正常工作,就我所研究的文档而言,大多数情况下都是PyMC3给出的示例,或者在所有情况下GP都没有与更简单的发行版组合在一起的情况,每次尝试运行模型时,我的整个Jupyter笔记本均无提示失败并重新启动。我遵循了文档建议,建议您生成先验后用作更大模型的一部分:
import pymc3 as pm
import numpy as np
# Import the data...
# Implement a hidden state model that captures yearly and within-year periodic trends, as well as using simple predictors.
with pm.Model() as model:
# We use a GaussianRandomWalk here, but could be other timeseries instead.
year_movement_sd = pm.Exponential('year_movement_sd', 10)
year_movement = pm.GaussianRandomWalk('year_movement', sd=year_movement_sd, shape=(num_years,))
periodic_period = pm.Normal('periodic_period', mu=6, sd=1)
periodic_psmooth = pm.Gamma('periodic_psmooth', alpha=4, beta=3)
periodic_cov = pm.gp.cov.Periodic(1, periodic_period, periodic_psmooth)
periodic_gp_latent = pm.gp.Latent(cov_func=periodic_cov)
periodic_gp_prior = periodic_gp_latent.prior('periodic_gp_prior', X=which_sixth) # I'ved tried this step with one-dimensional arrays, (1, 1)-shaped arrays, (n, 1) and (1, n) shaped arrays...
predictors_coeff = pm.Normal('predictors_coeff', mu=0, sd=100*2, shape=predictors_values.shape[1])
model_error = pm.HalfStudentT('model_error', nu=1.0, sd=100000)
productivity_obs = pm.Deterministic('productivity_obs', year_movement[year_values] + periodic_gp_prior + predictors_coeff*predictors_values)
with model:
# ... sample/fit the model. Currently using variational inference for speed until model works correctly.
我对使用PyMC3建模更复杂的模型还不是很陌生,但是以前在库中使用了层次模型。我在这里做错了什么(也许,我是否还需要将年度组成部分建模为较低级别的GP?),还是有一种更简单的方法来对周期性进行建模?