Sampling with while loop issue - Initialization always the same / resetting variable

You can do if/else logic but you can’t use the usual Python syntax. PyMC builds symbolic Theno graphs that are lazily evaluated (and which can be automatically differentiated).

Theano offers equivalent symbolic syntax to if/else and while/for loops, via theano.tensor.switch (works like numpy.where) and theano.scan, respectively.

This guide might give you some better understanding of this relationship: PyMC3 and Theano — PyMC3 3.11.5 documentation

You can also see some examples in our documentation, as well as Theano’s:

https://theano-pymc.readthedocs.io/en/latest/introduction.html

https://theano-pymc.readthedocs.io/en/latest/tutorial/index.html

You can use PyMC distributions with both of those (switch and scan) but they must be defined outside of the function calls.