I've encountered a problem while trying to replicate Gaussian Process simulation from the Users Guide (p. 167). I was trying to get used to the new syntax and redo some familiar analyses the new way, and this one seems broken.
Interestingly when I change ' i==j ? 0.1 : 0.0' to old version 'if_else(i==j, 0.1, 0.0)', I'm getting warnings from the parser, but everything works fine.
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] pl_PL.UTF-8/pl_PL.UTF-8/pl_PL.UTF-8/C/pl_PL.UTF-8/pl_PL.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rstan_2.11.1 StanHeaders_2.11.0 ggplot2_2.1.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.6 codetools_0.2-14 grid_3.3.1 plyr_1.8.4
[5] gtable_0.2.0 stats4_3.3.1 scales_0.4.0 labeling_0.3
[9] tools_3.3.1 munsell_0.4.3 parallel_3.3.1 rsconnect_0.4.3
[13] inline_0.3.14 colorspace_1.2-6 gridExtra_2.2.1
simulate_gp = "
data {
int<lower=1> N;
real x[N];
}
transformed data {
vector[N] mu;
cov_matrix[N] Sigma;
for (i in 1:N)
mu[i] = 0;
for (i in 1:N)
for (j in 1:N)
Sigma[i,j] = exp(-pow(x[i] - x[j],2))
+ i==j ? 0.1 : 0.0;
}
parameters {
vector[N] y;
}
model {
y ~ multi_normal(mu,Sigma);
}
"
simulate_gp_data = list("N" = 20,
"x" = seq(0,1,le=20))
simulate_gp_fit = stan(model_code = simulate_gp,
data = simulate_gp_data)
Error : model53762d492ad3_bc5595b9f9828bdf9502aead3874622e_namespace::model53762d492ad3_bc5595b9f9828bdf9502aead3874622e: Sigma is not positive definite:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
failed to create the sampler; sampling not done