Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
stan code for estimating Gaussian Process priors with squared exponential kernel. See: https://github.com/stan-dev/example-models/tree/master/misc/gaussian-process
// Sample from Gaussian process
// All data parameters must be passed as a list to the Stan call
// Based on original file from https://code.google.com/p/stan/source/browse/src/models/misc/gaussian-process/
data {
int<lower=1> N;
real x[N];
real eta_sq;
real rho_sq;
real sigma_sq;
}
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)
//// RBF, aka squared exp kernel, aka Gaussian
Sigma[i,j] <- eta_sq * exp(-rho_sq*pow(x[i] - x[j],2)) +
if_else(i==j, sigma_sq, 0.0);
}
parameters {
vector[N] y;
}
model {
y ~ multi_normal(mu,Sigma);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment