Created
May 28, 2020 15:45
-
-
Save trappmartin/a8ceb7e7b1ce20ac737ab599da432469 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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