brian-j-smith / Mamba.jl

Markov chain Monte Carlo (MCMC) for Bayesian analysis in julia
Other
253 stars 52 forks source link

Issue with non-diagonal covariance matrices in model definition #174

Open wlwetzel opened 1 year ago

wlwetzel commented 1 year ago

I was attempting to define a mamba model with a multivariate normal distribution for the data:

model = Model(
    PMT = Stochastic(1,
        (mu,sigma) -> MvNormal(mu,sigma),
        false),
    mu = Logical(1,
        (x,y) -> makeMeans(x,y)
        ),
    sigma = Logical(2 ,
        (x,y) -> makeCov(x,y)
        ),
    x = Stochastic(
        () -> Normal(0,1)
        ),
    y = Stochastic(
        () -> Normal(0,1)
        )
)

makeMeans and makeCov return a length 4 vector and a 4x4 matrix.

I get the following error when trying to run mcmc:

ERROR: MethodError: no method matching PDMats.PDMat(::ArrayLogical{2})
Closest candidates are:
  PDMats.PDMat(::AbstractMatrix, ::Cholesky) at ~/.julia/packages/PDMats/HCniD/src/pdmat.jl:12
  PDMats.PDMat(::Cholesky) at ~/.julia/packages/PDMats/HCniD/src/pdmat.jl:21
  PDMats.PDMat(::Symmetric) at ~/.julia/packages/PDMats/HCniD/src/pdmat.jl:20

I can run mcmc if I replace sigma with a scalar, so it seems it's an issue with using a matrix for the covariance.