Skip to content

Instantly share code, notes, and snippets.

@theogf
Last active May 23, 2019 10:54
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 theogf/9cdab4eaecdc5e7d80020a688fe03002 to your computer and use it in GitHub Desktop.
Save theogf/9cdab4eaecdc5e7d80020a688fe03002 to your computer and use it in GitHub Desktop.
Student-T GP Augmented model model
using Turing
using MLKernels
using LinearAlgebra
N=100
X = sort(rand(N,1),1) #Create some data
K = kernelmatrix(SquaredExponentialKernel(100.0),X) #Kernel matrix
y = rand(MvNormal(zeros(N),K+1e-1I)) #Sample from the GP prior with some noise
# Model representing Student-T Likelihood => Normal(y|f,omega)IG(omega|nu/2,nu/2)
@model augmentedmodel(K,y,nu,f=ones(N)) = begin
omega = Vector{Real}(undef,N)
for i in 1:N
omega[i] ~ InverseGamma(0.5*(nu+1.0),0.5*(nu+(y[i]-f[i])^2))
end
Sigma = Symmetric(inv(Diagonal(inv.(omega))+inv(K+1e-3I))) #Jittering is added on K
f ~ MvNormal(Sigma*(y./omega),Sigma)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment