Using pymc.potential to prevent evaluation of function at meaningless parameters values

202 views Asked by At

I am building a pymc model which must evaluate a very cpu expensive function (up to 1 sec per call on a very decent hardware). I am trying to limit the explored parameter space to meaningful solutions by means of a potential (the sum of a list of my variables has to stay within a given range). This works but I noticed that even when my potential returns an infinite value and forbids the parameters choice, this function gets evaluated. Is there a way to prevent that? Can one force the sampler to use a given evaluation sequence (pick up the necessary variables, check if the potential is ok and proceed if allowed)

I thought of using the potential inside the function itself and use it to determine whether it must proceed or immediately return, but is there a better way?

Jean-François

1

There are 1 answers

0
Juan M. Caicedo On BEST ANSWER

I am not aware of a way of ordering the evaluation of the potentials. This might not be the best way of doing so, but you might be able to check if the parameters are within reasonable at the beginning of the simulation. If the parameters are not within reasonable bounds you can return a value that will create your posterior to be zero.

Another option is to create a function for your likelihood. At the beginning of this function you could check if the parameters are within reasonable limits. If they are not you can return -inf without running your simulation. If they are reasonable you can run your model and calculate the log(p).

This is definitely not an elegant solution but it should work.

Full disclosure - I am not by any means a pymc expert.