Hi everyone,
I am working on a model that combines a Dirichlet Process (DDP) with a Gaussian Process (GP) prior. I have used a chunk of code for the GP prior from the Stan User’s Guide. However, I suspect that this part of the code is causing the model to take a very long time to converge.
Here’s a simplified version of the relevant part of my Stan code:
functions {
matrix L_cov_exp_quad_ARD(vector[] x,
real alpha,
vector rho,
real delta) {
int N = size(x);
matrix[N, N] K;
real sq_alpha = square(alpha);
for (i in 1:(N-1)) {
K[i, i] = sq_alpha + delta;
for (j in (i + 1):N) {
K[i, j] = sq_alpha
* exp(-0.5 * dot_self((x[i] - x[j]) ./ rho));
K[j, i] = K[i, j];
}
}
K[N, N] = sq_alpha + delta;
return cholesky_decompose(K);
}
}
data {
int<lower=1> N;
int<lower=1> D;
array[N] vector[D] x;
vector[N] y;
}
transformed data {
real delta = 1e-9;
}
parameters {
vector<lower=0>[D] rho;
real<lower=0> alpha;
real<lower=0> sigma;
vector[N] eta;
}
model {
vector[N] f;
{
matrix[N, N] L_K = L_cov_exp_quad_ARD(x, alpha, rho, delta);
f = L_K * eta;
}
rho ~ inv_gamma(5, 5);
alpha ~ std_normal();
sigma ~ std_normal();
eta ~ std_normal();
y ~ normal(f, sigma);
}
[edit: end code format block]
Issue:
The sampling process is extremely slow, and the model takes a very long time to converge.
Request:
Can anyone suggest how I might optimize this part of the code to improve convergence speed? Are there specific techniques or modifications that can make the GP prior more computationally efficient in Stan?
Thank you for your help!