I am trying to fit my experimental data( ~40k circular data, [-\pi, +\pi], bimodal) with mixture of von mises distribution using Mamba.
I want to predict the parameters(\mu, \kappa, weights) of the data.
Problem
The following code returns
TypeError: in new, expected ScalarStochastic, got Float64
However, I can’t figure out what is wrong with my code…
How can I fix this error?
Any suggestions are welcomed !!
Thank you in advance.
Dependencies and data
# Julia version 1.2.0
using Mamba # v0.12.2
using Distributions # v0.21.8
data = Dict{Symbol, Any}(
:sample => Array(data[:, 1]),
:N => length(data[:, 1]),
)
"""
Dict{Symbol,Any} with 2 entries:
:N => 374718
:sample => [2.49329, 0.143419, -1.23308, 2.42615, -1.74222, -0.180238, 0.3280…
"""
Model specification
\kappa1 \sim Gamma(\alpha=1., \beta=1.0)\\ \kappa2 \sim Gamma(\alpha=1., \beta=1.0)\\ \mu1 \sim VonMises(\mu=0, \kappa=0.5)\\ \mu2 \sim VonMises(\mu=pi, \kappa=0.5)\\ w \sim Dirichlet([1., 1.])\\ y \sim w[1]*VonMises(\mu=\mu1, \kappa=\kappa1) + w[2]*VonMises(\mu=\mu2, \kappa=\kappa2)
model = Model(
kappa1 = Stochastic(
() -> Gamma(),
),
kappa2 = Stochastic(
() -> Gamma(),
),
mu1 = Stochastic(
() -> VonMises(0, 0.5),
),
mu2 = Stochastic(
() -> VonMises(pi, 0.5),
),
w = Stochastic(1,
() -> Dirichlet(ones(2))
),
y = Stochastic(1,
(mu1, mu2, kappa1, kappa2, w) ->
MixtureModel(VonMises[VonMises(mu1, kappa1), VonMises(mu2, kappa2)], w),
false),
)
scheme = [NUTS([:kappa1, :kappa2, :mu1, :mu2, :w])]
setsamplers!(model, scheme)
Initial values and sampling
inits = [
Dict{Symbol, Any}(
:y => data[:sample],
:kappa1 => rand(Gamma(1, 1)),
:kappa2 => rand(Gamma(1, 1)),
:mu1 => rand(VonMises(0, 0.5)),
:mu2 => rand(VonMises(0, 0.5)),
:w => [0.5, 0.5]
)
]
## MCMC(NUTS)
nuts_inference = mcmc(model, data, inits, 5000, burnin=1000, thin=2, chains=1)
returns
TypeError: in new, expected ScalarStochastic, got Float64