问题描述
我正在尝试根据高斯随机游走对参数进行采样。 在 R 中,代码如下所示:
#simulate a Gaussian random walk
#N : number of steps
#x0 : initial offset
#mu : drift veLocity
#variance : step size
Gauss_RandomWalk <- function(N,x0,mu,variance) {
z <- cumsum(rnorm(n=N,mean=mu,sd=sqrt(variance)))
t <- 1:N
x <- (x0 + t*mu + z)
return(x)
}
实际上,设置 x0=0.
、mu=0.
、variance=0.035**2
时的结果看起来不错且合理:
[1] 0.040703269 0.009159686 0.052360030 0.059352074 0.092739218 0.098240752 0.113957813 0.064187776
[9] 0.062757728 0.063948224 0.034591074 0.004828493 0.019809969 0.032135111 0.025692763 -0.031678858
[17] -0.048033007 -0.020708105 -0.032231674 0.004917305 0.030961430 0.099054042 0.043441737 -0.010513085
每当我尝试在 Stan 中执行此操作时,例如根据 here 表示的内容:
// model to be fitted
model {
sqrtQ ~ student_t(2,0.035);
// here we define the random walk for the log_Rt parameter
log_Rt[1] ~ normal(0.,0.035);
for (t in 2:number_days) {
log_Rt[t] ~ normal(log_Rt[t-1],sqrtQ);
}
print(log_Rt);
(...)
}
结果并不好。举个例子,跳跃 -0.839043 -> 1.91956
大约是标准偏差的 85 倍,在统计上是不可能的......但为什么会发生这种跳跃?
Chain 1: [0.382303,-0.489057,0.33374,-0.839043,1.91956,0.249953,-1.88793,1.61106,1.11189,-0.725063,-0.513174,1.79012,1.57758,0.75819,0.525524,1.44762,1.19118,0.485563,-1.48318,-1.36389,1.96355,0.321416,-0.365132,-0.644287,0.0981577,1.02943,-1.27993,-1.98085,-1.75191,-1.76489,1.60888,1.48925,-0.0452427,-0.92583,-1.21594,-0.906329,-0.700237,-0.208039,0.493656,0.490295,-1.61091,1.94587,0.758567,-1.02318,-1.92659,-0.999492,1.78042,0.214125,-0.0158054,-0.753422,.......
编辑:我也试过了:
// model to be fitted
model {
// here we define the random walk for the log_Rt parameter
log_Rt[1] ~ normal(0.,0.035);
}
print(log_Rt);
(...)
}
但事情根本没有改变。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)