ICB-DCM / pyABC

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

How can I set constraints between model parameters? #558

Closed xieduo7 closed 2 years ago

xieduo7 commented 2 years ago

Hi, the developers and users of pyABC,

Can pyABC support any function which can express constraints between model parameters?

For example, I want to estimate two parameters (theta1 and theta2) using pyABC, and I want to set a constriant condition in these two parameters (theta1 > theta2) when I randomly choose prior parameters (theta1 and theta2). If it is not the case, this prior sampling will not pass to the ABC function.

I know there is a prior_test option in the ABC_sequential function of R package EasyABC which can do this. Is there any equivalent to the prior_test option of EasyABC in pyABC?

I have tried to add a line of conditional code but it didn't work well:

def model(theta1, theta2):
    if theta1 > theta2:
       do something
       return something
    else:
      return None

Do you have any suggestions? Or should I modify the source code of the pyABC package? Thank you!

Best, Duo

yannikschaelte commented 2 years ago

Hi, this is possible by extending the Distribution class and implementing the rvs() and pdf() methods. As this has been asked multiple times, I will try to provide a notebook demonstrating non-independent priors next week!

xieduo7 commented 2 years ago

Hi @yannikschaelte,

Thank you for your quick response. Looking forward to the notebook!

Best, Duo

yannikschaelte commented 2 years ago

Dear @xieduo7 , an example is now given in https://pyabc.readthedocs.io/en/develop/examples/custom_priors.html

xieduo7 commented 2 years ago

Hi @yannikschaelte,

Thank you for your example. I will try it!

Best, Duo