bat / BAT.jl

A Bayesian Analysis Toolkit in Julia
Other
198 stars 30 forks source link

`HamiltonianMC()` is failed on the tutorial model #426

Closed takuizum closed 10 months ago

takuizum commented 11 months ago

Hello, everyone,

I'm trying out BAT.jl out of curiosity. I found that HamiltonianMC() does not work on the tutorial model. More specifically, in the tutorial, the following syntax is used to sample from the posterior of the model.

samples = bat_sample(posterior, MCMCSampling(mcalg = MetropolisHastings(), nsteps = 10^5, nchains = 4)).result

Changing mcalg = HamiltonianMC(), return an error.

ERROR: Density evaluation with logdensityof failed at [NaN, NaN, NaN, NaN, NaN], must not evaluate to NaN, density is DistMeasure(objectid = 0x81ff2597fbd0fd5d, varshape = ValueShapes.ArrayShape{Real, 1}((5,)))

It would be greatly appreciated if someone could help with this problem.

Thank you,

oschulz commented 11 months ago

Hi, sorry @takuizum , your issue got overlooked somehow. I'll check what's wrong there.

oschulz commented 10 months ago

This seems to be an intermittent error, I'm tracking it down.

oschulz commented 10 months ago

This seems to occur when the parameters go to regions in which the expected counts in one of the histograms bins becomes zero. In that case, this happens:

julia> f = v -> logpdf(Poisson(v), 1)
#32 (generic function with 1 method)

julia> f(0.0)
-Inf

julia> ForwardDiff.derivative(f, 0.0)
NaN

We didn't run this tutorial with HMC often, in the past, that may be why we overlooked this "bug" in the likelihood.

oschulz commented 10 months ago

@takuizum this should be fixed now in the tutorial.