Random.seed!(3)
N = 30
μs = [-3.5, 0.0]
x = mapreduce(c -> rand(MvNormal([μs[c], μs[c]], 1.), N), hcat, 1:2)
using Turing, MCMCChains
model GaussianMixtureModel(x) = begin
D, N = size(x)
# Draw the parameters for cluster 1.
μ1 ~ Normal()
# Draw the parameters for cluster 2.
μ2 ~ Normal()
μ = [μ1, μ2]
# Uncomment the following lines to draw the weights for the K clusters
# from a Dirichlet distribution.
# α = 1.0
# w ~ Dirichlet(2, α)
# Comment out this line if you instead want to draw the weights.
w = [0.5, 0.5]
# Draw assignments for each datum and generate it from a multivariate normal.
k = Vector{Int}(undef, N)
for i in 1:N
k[i] ~ Categorical(w)
x[:,i] ~ MvNormal([μ[k[i]], μ[k[i]]], 1.)
end
return k
end
gmm_sampler = Gibbs(PG(100, :k), HMC(0.05, 10, :μ1, :μ2))
gives me the error
gmm_sampler = Gibbs(PG(100, :k), HMC(0.05, 10, :μ1, :μ2))
ERROR: MethodError: no method matching PG(::Int64, ::Symbol)
Closest candidates are:
PG(::Int64, ::Int64) at /home/brett/.julia/packages/Turing/YnwiD/src/samplers/pgibbs.jl:34
PG(::Int64, ::Int64, ::F, ::Set{T}, ::Int64) where {T, F} at /home/brett/.julia/packages/Turing/YnwiD/src/samplers/pgibbs.jl:28
PG(::Int64, ::Int64, ::Any...) at /home/brett/.julia/packages/Turing/YnwiD/src/samplers/pgibbs.jl:38
Stacktrace:
[1] top-level scope
@ REPL[16]:1
what is wrong with k. Is k supposed to be an integer instead of a vector. I’m not sure what k is between anyhow.