Incorperating numerical approximations into model

You can’t mix numpy/scipy with pytensor (the computational backend for PyMC) – this is the source of your error.

To fix it, you have several options:

  1. Wrap your optimizer into a pytensor Op, see here for example. The cost of this will be that you can’t use NUTS, because your optimizer Op won’t have gradients.

  2. You could also try to re-write your optimizer using only pytensor functions, see here for an example of multivariate Newton’s method with line search.

  3. Final option, write your model in JAX and use jaxopt, then wrap the jax model into pytensor: see here and here for examples doing this.