Hello Guys,
I’m trying to model a time series using a Gaussian process, akin to do a time series decomposition similar to the birthday model, but I get stuck when trying to sample from the prior. I read the chapter about the birthday model in the Bayesian Workflow book and started out with the code from there, but then decided to not use the Hilbert space basis functions in my first iteration, because they looked a bit intimidating to me and I wanted to get going quickly.
Here is my code:
data {
int<lower=1> N;
vector[N] x;
}
transformed data {
vector[N] mu = rep_vector(0, N);
}
parameters {
real<lower=0,upper=N> rho;
real<lower=0> alpha;
vector[N] y_sim;
}
model {
matrix[N, N] L_K;
rho ~ std_normal();
alpha ~ std_normal();
matrix[N, N] K = gp_exp_quad_cov(to_array_1d(x), 1.0, 1.0) + diag_matrix(rep_vector(1e-10, N));
L_K = cholesky_decompose(K);
y_sim ~ multi_normal_cholesky(rep_vector(0, N), L_K);
}
The values in x
are just the integers from 1 to 582. However, despite taking very long, I get
Chain [1] Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain [1] Exception: gp_exp_quad_cov: sigma is 0, but must be positive! (in ‘sim.stan’, line 23, column 2 to column 99)
Chain [1] If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain [1] but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
basically all the time. When I set rho
and alpha
to concrete 1.0, the informational message disappears and the code runs fine (but still takes very long.)
I must be doing something fundamentally wrong. Any help is appreciated!