Skip to content

Instantly share code, notes, and snippets.

@trappmartin
Created May 28, 2020 15:45
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 trappmartin/a8ceb7e7b1ce20ac737ab599da432469 to your computer and use it in GitHub Desktop.
Save trappmartin/a8ceb7e7b1ce20ac737ab599da432469 to your computer and use it in GitHub Desktop.
using Turing
using Bijectors
using LinearAlgebra
Bijectors.bijector(d::LKJ) = PDBijector()
@model function correlation(y)
N,D = size(y)
mu ~ filldist(truncated(Normal(0, 100), -10, 10), D)
sigma ~ filldist(truncated(Normal(0, 100), 0, 10), D)
# prior on the correlation matrix
rho ~ LKJ(D,D)
L = Diagonal(sigma) * rho
# Iterate through each datapoint, and observe its likelihood.
for i in 1:N
y[i,:] ~ MvNormal(mu , L*L')
end
return L*L'
end
cov = [ 4.94072998 -4.93536067; -4.93536067 5.99552455 ]
x = rand(MvNormal([0.0, 1.0], cov), 10)
model = correlation(x')
sample(model, HMC(0.01,5), 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment