Prior using past trace information?

Hi there,
It’s probably a random and silly question but is there any way to define a prior with pm.Potential that would be some kind of function of the variable so far at the time of the draw? For instance a prior with tt.switch that depends on the mean of the chain so far?

Perhaps it could be done by using a shared variable and then writing a callback to adjust its value on every iteration.

I didn’t know the callback possibility and will investigate this, based on Sample callback — PyMC3 3.10.0 documentation. Looks like it’s not available for SMC though, which is too bad.

Another potentially more complicated option is to write a custom step method that is only used to update the value of some input to your pm.Potential object. However, you’ll probably have to keep track of some state outside of the step method (which normally just communicates with the other samplers via a Point object). I think this is a neat problem and would be happy to mock up something simple.

I had some fun trying the callback feature, it’s really useful but I’m afraid I would need to think about it some more for the exact application I had in mind. It works in the sense that I can update a variable that uses the trace information up until the draw/chain, which is great and precisely what I wanted, but the problem is that my algorithm is still flawed. A more complicated solution like the other one you suggest would probably not change this I’m afraid. Anyway, thanks a lot for your help!