ICB-DCM / pyABC

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

Explanation Warning message #574

Closed LeaBro closed 2 years ago

LeaBro commented 2 years ago

Hi,

as I was using the pyabc-package for parameter fitting, I had to play around with different bounds for prior parameters and tried different datasets. I am using lognormal priors and the multivariate transition kernel. At different occasions, I ran into this warning message:

"WARNING:pyabc.util:Unusually many (model, parameter) samples have prior density zero. The transition might be inappropriate."

Since this warning did not seem to obstruct the run itself, I could continue my analysis. Anyway, it might be useful to learn more about the reason behind it. Can anyone explain to me how this warning effects the process/results of parameter fitting and what the trigger is for it to show up? It has been difficult to find where the warning is raised within the source code.

Greets, Lea

yannikschaelte commented 2 years ago

Hi, that warning would be raised here https://github.com/ICB-DCM/pyABC/blob/main/pyabc/inference_util.py#L191. What happens here is that parameters are sampled from the transition kernel, and then compared to the prior to make sure the prior is positive, as otherwise that particle would be assigned a zero weight later. This warning may happen e.g. if your prior is bounded, and the transition suggests many values outside the boundaries, or e.g. if you have discrete parameters.

LeaBro commented 2 years ago

Hi, does this imply the transition kernel is wanting to sample values from outside the bounds that I have specified? I thought in that case it could help to use wider bounds, but it did not. Do you know a general solution to this issue? Or should I continue to ignore it?

yannikschaelte commented 2 years ago

Hi, this would be one explanation. You could plot the posterior distributions you obtain vs the prior, to see whether these concentrate (for single parameters) on the edge.

I would advise to not ignore the issue, but to see what is happening, as it never occurred for me, and could indicate sth is wrong (it used to be an error, just recently became a warning).

yannikschaelte commented 2 years ago

Closing due to inactivity. Feel free to re-open if the issue persists!

thejasvibr commented 8 months ago

Hi, I'm writing with regards to the same warning. I have a simulation model that is very intensive to run, and so I'm hoping to do parameter inference on 'R', from a discrete set of parameter values in the 'R_val' np.array. Here I tried to formulate the indices of each R value as a scipy.randint distribution.

priors_v2 = pyabc.Distribution(calldirection=pyabc.RV("uniform", 0, 2*np.pi*0.9),
                           R_ind=pyabc.RV("randint", 0, R_val.size))

However, for some reason the ABCSMC run seems to get stuck after the warning and doesn't show progress.

Are there are any alternative formulations I can use to perform parameter inference on discrete variables? I did manage to 'fool' the ABCSMC by treating 'R' as a truly continuous variable, but the simulation chooses the nearest value in the R_val array . This roundabout method seems to be indirect in terms of interpretation, and perhaps also may take much longer as the ABC tries to take small jumps in various directions but often lands on the same discrete values?

I'm running a Windows 10, pyabc version 0.12.13

==============UPDATE===== Apologies for not checking in more detail. Managed to successfully get the discrete parameter inference going using the example code in here.


# priors
priors_v2 = pyabc.Distribution(calldirection=pyabc.RV("uniform", 0, 2*np.pi*0.9),
                           R_candidate=pyabc.RV('rv_discrete',
                                          values=(R_val, [1/R_val.size]*R_val.size)))

# transition kernels
transition = pyabc.AggregatedTransition(
    mapping={
        'R_candidate': pyabc.DiscreteJumpTransition(
            domain=R_val, p_stay=0.7
        ),
        'calldirection': pyabc.MultivariateNormalTransition(),
    }
)