Handling Likelihood Computation with Matrix Priors

Three quick things:

  • you never want to to use numpy functions inside a PyMC model
  • you never want to call .eval() on a random variable inside a PyMC model definition
  • you never want to use loopsinside a PyMC model definition

You should use PyTensor functions (which mirror the numpy API) instead of numpy functions and vectorize any loops. Doing both of these things will alleviate the need to call .eval().

There are a couple of catches (e.g., things like theta_matrix_np[j,i] = theta_val needs to be re-written using pt.set_subtensor()^1), but otherwise you should be able to adapt your code relatively straightforwardly.

^1 You may not need this once you vectorize this loop.