rand(::NormalWishart) is broken
jaak-s opened this issue · comments
It seems the random generator for NormalWishart
is broken after the code has been separated from Distributions:
mu0 = [2., 3.]
kappa0 = 3.
nu0 = 4.
T0 = eye(2)
T0[1,2] = T0[2,1] = .5
pri = ConjugatePriors.NormalWishart(mu0, kappa0, T0, nu0)
ConjugatePriors.rand(pri)
ERROR: `rand` has no method matching rand(::Wishart{PDMat})
you may have intended to import Base.rand
in rand at /home/jaak/.julia/v0.3/ConjugatePriors/src/normalwishart.jl:78
One solution is to replace rand
into Distributions.rand
in lines normalwishart.jl:78 and 79. Maybe some other solution is better.
I think we should import rand
from Distributions
here.
I was trying to verify that this was fixed by #6, but now I'm getting
julia> ConjugatePriors.rand(pri)
ERROR: error compiling rand: error compiling _wishart_genA: could not load library "libRmath-julia"
dlopen(libRmath-julia.dylib, 1): Library not loaded: libdSFMT.dylib
Referenced from: /Users/kevin/Source/julia/usr/lib//libRmath-julia.dylib
Reason: image not found
/Users/kevin/Source/julia/usr/lib/libdSFMT.dylib
exists, so I'm wondering if something is screwed up with the (julia) Makefile, or just my install.
Can someone else test this?
FWIW, I fixed this with
make -C deps clean-dsfmt clean-Rmath-julia
make -j
I tested the code in this issue, and got
julia> import ConjugatePriors
INFO: Recompiling stale cache file /Users/kevin/.julia/lib/v0.4/Compat.ji for module Compat.
INFO: Recompiling stale cache file /Users/kevin/.julia/lib/v0.4/PDMats.ji for module PDMats.
INFO: Recompiling stale cache file /Users/kevin/.julia/lib/v0.4/ArrayViews.ji for module ArrayViews.
INFO: Recompiling stale cache file /Users/kevin/.julia/lib/v0.4/StatsFuns.ji for module StatsFuns.
INFO: Recompiling stale cache file /Users/kevin/.julia/lib/v0.4/Distributions.ji for module Distributions.
INFO: Recompiling stale cache file /Users/kevin/.julia/lib/v0.4/StatsBase.ji for module StatsBase.
julia> pri = ConjugatePriors.NormalWishart(mu0, kappa0, T0, nu0)
ConjugatePriors.NormalWishart(
dim: 2
zeromean: false
mu: [2.0,3.0]
kappa: 3.0
Tchol: Base.LinAlg.Cholesky{Float64,Array{Float64,2}} with factor:
2x2 UpperTriangular{Float64,Array{Float64,2}}:
1.0 0.5
0.0 0.866025
nu: 4.0
)
julia> ConjugatePriors.rand(pri)
([2.1111547514545275,2.797861105606972],
2x2 Array{Float64,2}:
4.60547 2.91226
2.91226 3.36429)
So, it should finally be fixed. Cheers!