Sometimes, but not always, this error is thrown for the model below when using the SMC() sampler:
ERROR: LoadError: CTaskException:
MethodError: Cannot `convert` an object of type Geometric{Float64} to an object of type Dirac{Float64}
Closest candidates are:
convert(::Type{T}, ::T) where T at essentials.jl:205
Dirac{T}(::Any) where T at /home/hakank/.julia/packages/Distributions/Xrm9e/src/univariate/discrete/dirac.jl:22
Here’ s the model (it’s a port of a BLOG model for counting the number of logins for honest/dishonest people):
using Turing
@model function person_login()
# Number of people (exclude 0 people)
numPeople ~ truncated(Poisson(5),0,Inf)
# Is this person honest?
honest ~ filldist(Bernoulli(0.9),numPeople)
# An honest person have just one login
login = tzeros(numPeople)
for p in 1:numPeople
if honest[p] == true
login[p] ~ Dirac(1.0)
else
login[p] ~ Geometric(0.8)
end
end
end
model = person_login()
chns = sample(model, SMC(), 10_000)
display(chns)
Why does this sometimes work and sometimes not? And: is there another way to state this in a better way:
for p in 1:numPeople
if honest[p] == true
login[p] ~ Dirac(1.0)
else
login[p] ~ Geometric(0.8)
end
end
It don’t seems to matter what the probability of honest
is, I got the same error for probability of honest is 0.5 as for 0.90.
Versions:
- Julia: v1.6.2
- Turing v0.16.6
- Distributions v0.24.18
I should also mention that other samplers (always) give some different errors:
- Running PG(5) throws
DimensionMismatch("tried to assign 5 elements to 6 destinations")
- MH():
LoadError: DimensionMismatch("Inconsistent array dimensions.")
So something is weird with this model…