I am trying to learn how to use the Mamba package in Julia for doing Bayesian inference. Though the package is great, as a beginner I find the documentation a bit scarce in information. Hence I am trying to figure out how implement some very simple examples.
What I have tried
I implemented an example for doing Bayesian inference for the mean of a univariate normal distribution. The code follows:
using Mamba
## Model Specification
model = Model(
x = Stochastic(1,
mu -> Normal(mu, 2.0),
false
),
mu = Stochastic(
() -> Normal(0.0, 1000.0),
true
)
)
## Data
data = Dict{Symbol, Any}(
:x => randn(30)*2+13
)
## Initial Values
inits = [
Dict{Symbol, Any}(
:x => data[:x],
:mu => randn()*1
)
]
## Sampling Scheme Assignment
scheme1 = NUTS([:mu])
setsamplers!(model, [scheme1])
sim1 = mcmc(model, data, inits, 10000, burnin=250, thin=2, chains=1);
describe(sim1)
This seems to work absolutely fine (though there may be better ways perhaps of coding this?).
What I am trying to do and doesn't work.
In this example, I am trying to do bayesian inference for the mean of a bivariate normal distribution. The code follows:
using Mamba
## Model Specification
model = Model(
x = Stochastic(1,
mu -> MvNormal(mu, eye(2)),
false
),
mu = Stochastic(1,
() -> MvNormal(zeros(2), 1000.0),
true
)
)
## Data
data = Dict{Symbol, Any}(
:x => randn(2,30)+13
)
## Initial Values
inits = [
Dict{Symbol, Any}(
:x => data[:x],
:mu => randn(2)*1
)
]
## Sampling Scheme Assignment
scheme1 = NUTS([:mu])
setsamplers!(model, [scheme1])
sim1 = mcmc(model, data, inits, 10000, burnin=250, thin=2, chains=1);
describe(sim1)
As you may notice, the changes that I suppose are necessary are minimal. However, I am doing somewhere something wrong and when I attempt to run this I get an error (a conversion between types error) which does not help me further.
Any help appreciated. If this works out, I will consider contribute this simple example to the Mamba documentation for other new users. Thanks.
Addendum: the error message
ERROR: MethodError: Cannot `convert` an object of type Array{Float64,2} to an object of type Array{Float64,1}
This may have arisen from a call to the constructor Array{Float64,1}(...),
since type constructors fall back to convert methods.
in setinits!(::Mamba.ArrayStochastic{1}, ::Mamba.Model, ::Array{Float64,2}) at /lhome/lgiannins/.julia/v0.5/Mamba/src/model/dependent.jl:164
in setinits!(::Mamba.Model, ::Dict{Symbol,Any}) at /lhome/lgiannins/.julia/v0.5/Mamba/src/model/initialization.jl:11
in setinits!(::Mamba.Model, ::Array{Dict{Symbol,Any},1}) at /lhome/lgiannins/.julia/v0.5/Mamba/src/model/initialization.jl:24
in #mcmc#29(::Int64, ::Int64, ::Int64, ::Bool, ::Function, ::Mamba.Model, ::Dict{Symbol,Any}, ::Array{Dict{Symbol,Any},1}, ::Int64) at /lhome/lgiannins/.julia/v0.5/Mamba/src/model/mcmc.jl:29
in (::Mamba.#kw##mcmc)(::Array{Any,1}, ::Mamba.#mcmc, ::Mamba.Model, ::Dict{Symbol,Any}, ::Array{Dict{Symbol,Any},1}, ::Int64) at ./<missing>:0