ICB-DCM / pyABC

distributed, likelihood-free inference
https://pyabc.rtfd.io
BSD 3-Clause "New" or "Revised" License
206 stars 44 forks source link

RuntimeWarning: divide by zero encountered in double_scalars #623

Closed jack-pan-ai closed 1 year ago

jack-pan-ai commented 1 year ago

Bug description RuntimeWarning: divide by zero encountered in double_scalars

I construct a model with 8 parameters and then modify the template in the example to adapt the model. And then, I found the warning when I increased the population from 5 to 10,

RuntimeWarning: divide by zero encountered in double_scalars weight = acceptance_weight * prior_pd / transition_pd

This warning will lead to the crush of the run() because it cannot deal with the nan in the weight, such as AssertionError: The population total weight nan is not normalized.

Expected behavior The transition_pd should be strictly large than 0;

Environment Name: pyabc Version: 0.12.13 Python 3.10.9 system: Ubuntu]

stephanmg commented 1 year ago

Hello, could you please provide the template and the model code if possible?

stephanmg commented 1 year ago

Potentially same issue as #614

jack-pan-ai commented 1 year ago

Hello, could you please provide the template and the model code if possible?

Thanks very much for your reply, the template I am using is https://pyabc.readthedocs.io/en/latest/examples/parameter_inference.html

I did thought it is the same problem with #614 where the transition pdf is 0 leading to the Nan value in the normalization.

The modified code I am using is in the abc_rainfall.ipynb file (google cloud), where

https://drive.google.com/file/d/1unPilmUt58Pxc6-DYf9qj7ceJoEshdGC/view?usp=drive_link

stephanmg commented 1 year ago

Can't see any suspicious there, pulling in @arrjon if he know something.

arrjon commented 1 year ago

The problem seems to lie in the transition kernel. Changing to a local transition instead of using a multivariate normal kernel seems to solve the issue:

abc = pyabc.ABCSMC(model, prior, distance, 
                   transitions= pyabc.LocalTransition(),
                   summary_statistics=summary_statistics, population_size=50)

The transition kernel should ideally be kind of similar to the unknown posterior. You can find more details here in this nice paper.

stephanmg commented 1 year ago

Feel free to re-open if @arrjon's solution does not work.

jack-pan-ai commented 1 year ago

The problem seems to lie in the transition kernel. Changing to a local transition instead of using a multivariate normal kernel seems to solve the issue:

abc = pyabc.ABCSMC(model, prior, distance, 
                   transitions= pyabc.LocalTransition(),
                   summary_statistics=summary_statistics, population_size=50)

The transition kernel should ideally be kind of similar to the unknown posterior. You can find more details here in this nice paper.

great thanks! It does work!!