Skip to content

Instantly share code, notes, and snippets.

Last active May 27, 2016 17:51
What would you like to do?
stan code for estimating Gaussian Process priors with squared exponential kernel. See:
// Sample from Gaussian process
// All data parameters must be passed as a list to the Stan call
// Based on original file from
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