Hi. Because I also stumbled upon such an issue I investigated a bit my model and I managed to narrow it down to:
"""
data : `Vector` of data
len: length of data (for prior analyisis)
"""
@model function attemptlinkedvi(data, len=missing)
if data === missing
data = Vector{Int}(undef, len)
end
μ = 100
σ = 100
prior ~ truncated(Normal(μ,σ),0,Inf)
data ~ filldist(Exponential(prior), 20)
end
This model fits the data fine.
If I substitute σ = 100
with σ = Exponential(100)
and then I get unending complaints about attempting to link a linked vi.
In both cases sampling the prior without respect to data works fine.
Warnings
┌ Warning: The current proposal will be rejected due to numerical error(s).
│ isfinite.((θ, r, ℓπ, ℓκ)) = (true, true, false, true)
└ @ AdvancedHMC ~/.julia/packages/AdvancedHMC/iWHPQ/src/hamiltonian.jl:47
┌ Warning: [DynamicPPL] attempt to link a linked vi
└ @ DynamicPPL ~/.julia/packages/DynamicPPL/zPOYL/src/varinfo.jl:821
┌ Warning: [DynamicPPL] attempt to link a linked vi
└ @ DynamicPPL ~/.julia/packages/DynamicPPL/zPOYL/src/varinfo.jl:821
┌ Warning: The current proposal will be rejected due to numerical error(s).
│ isfinite.((θ, r, ℓπ, ℓκ)) = (true, true, false, true)
└ @ AdvancedHMC ~/.julia/packages/AdvancedHMC/iWHPQ/src/hamiltonian.jl:47
┌ Warning: [DynamicPPL] attempt to link a linked vi
└ @ DynamicPPL ~/.julia/packages/DynamicPPL/zPOYL/src/varinfo.jl:821
┌ Warning: [DynamicPPL] attempt to link a linked vi
└ @ DynamicPPL ~/.julia/packages/DynamicPPL/zPOYL/src/varinfo.jl:821
┌ Warning: The current proposal will be rejected due to numerical error(s).
│ isfinite.((θ, r, ℓπ, ℓκ)) = (true, true, false, true)
└ @ AdvancedHMC ~/.julia/packages/AdvancedHMC/iWHPQ/src/hamiltonian.jl:47
┌ Warning: [DynamicPPL] attempt to link a linked vi
└ @ DynamicPPL ~/.julia/packages/DynamicPPL/zPOYL/src/varinfo.jl:821
┌ Warning: [DynamicPPL] attempt to link a linked vi
└ @ DynamicPPL ~/.julia/packages/DynamicPPL/zPOYL/src/varinfo.jl:821
┌ Warning: The current proposal will be rejected due to numerical error(s).
│ isfinite.((θ, r, ℓπ, ℓκ)) = (true, true, false, true)
└ @ AdvancedHMC ~/.julia/packages/AdvancedHMC/iWHPQ/src/hamiltonian.jl:47
I figured that it may be due to the truncated
, i.e. MCMC samples the whole Normal
and if the samplings are outside what the truncated
requires it rejects the proposal.
So I substituted the truncated(Normal)
with a strictly positive distribution Gamma
, i.e. :
@model function attemptlinkedvi(data, len=missing)
if data === missing
data = Vector{Int}(undef, len)
end
μ = 100
σ ~ Exponential(100)
prior ~ Gamma(μ/σ, σ)
data ~ filldist(Exponential(prior), 20)
end
and it fits nicely !
Still I am not sure if my hypothesis was correct, but this certainly suggests that sampling truncated distributions comes with some pitfalls.
@juliohm Can you remember if you also had similar truncated
distributions in your model maybe ?
It would be nice to have an opinion of a Turing developer.