Skip to content

Instantly share code, notes, and snippets.

@mrecos
Last active May 27, 2016 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrecos/fb67f33cc13baa6e3af8afba4fd0f333 to your computer and use it in GitHub Desktop.
Save mrecos/fb67f33cc13baa6e3af8afba4fd0f333 to your computer and use it in GitHub Desktop.
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