Boolean operations support for theano.tensor

My model consists of two simple distributions (a=DiscreteUniform and b=Uniform) and an additional extension of Discrete with my own implementation of logp.

My custom logp implementation is pretty complicated (running a tree search mechanism with the values of a and b as parameters). The values of a and b are used in various ways. For example to determine an order in a priority queue.
I keep getting “TypeError: Variables do not support boolean operations.”. I guess this is because <=,==,> operations are not supported by theano.tensor. (I’m using numpy 1.13).

However, this seems like a trivial modeling issue. What is the right way to tackle this? what is a good workaround?

I’ve tried to call eval(), cast to floats/ints… nothing works.


It is hard to be sure without any code, but from what I understand the problem is probably that your custom logp implementation doesn’t work with theano variables. Comparisons are in principle supported by theano, but the results can’t be used in if, for or while statements. Since you seem to have only two parameters, you probably don’t really need gradients. Metropolis should still work here. So you could wrap your custom logp function with as_op (see the docs for an example). If you want to get an overview about how theano works with pymc3, you can have a look an introduction (still wip):

1 Like