JuliaMath / MeasureTheory.jl

"Distributions" that might not add to one.
MIT License
386 stars 32 forks source link

`testvalue(::MvNormal)` fails #206

Closed mschauer closed 2 years ago

mschauer commented 2 years ago
using Tilde
model = @model (y, L) begin
    n = length(y)
    η ~ Tilde.MvNormal(μ=zeros(n), σ=L)
    for j in 1:n
        y[j] ~ Tilde.Bernoulli(logitp = η[j])
    end
end
y1 = rand(Bool, 10)
L1 = randn(10,10)
post = model(y1, L1) | (;y1)
ℓ1(θ) = logdensityof(post, (;η=θ))
ℓ1(rand(10))

works. But

ℓ(θ) = logdensityof(post, transform(as(post), θ))
ℓ(rand(10))

gives

ERROR: StackOverflowError:
Stacktrace:
 [1] testvalue(μ::MeasureTheory.OrthoLebesgue{(:μ, :σ), Tuple{Vector{Float64}, Matrix{Float64}}}) (repeats 79984 times)
   @ MeasureBase ~/.julia/packages/MeasureBase/uCYyk/src/utils.jl:12
cscherrer commented 2 years ago

Thanks @mschauer . The problem is here:

julia> testvalue(MvNormal(σ=[1 0; 0 1]))
ERROR: StackOverflowError:
Stacktrace:
 [1] testvalue(μ::MeasureTheory.OrthoLebesgue{(:σ,), Tuple{Matrix{Int64}}}) (repeats 79984 times)
   @ MeasureBase ~/.julia/packages/MeasureBase/uCYyk/src/utils.jl:12

runtests.jl has this function

function test_measure(μ)
    logdensity_def(μ, testvalue(μ)) isa AbstractFloat
end

that would check for this, but MvNormal is currently missing. That's how this slipped through the cracks.

Working on a fix now.