Is it possible to use Pyro’s normalizing flows for posterior inference with an R-based likelihood and prior

Hi, I have a high-dimensional posterior that I want to estimate based on a given likelihood and prior. My likelihood is a D×D multivariate Cauchy distribution, and I want to shrink this using an adaptive shrinkage prior, which is an empirically driven mixture of normal distributions as described in the ashr package (GitHub - stephens999/ashr: An R package for adaptive shrinkage).

Currently, my likelihood and prior are fully defined and computed in R, and I’d like to infer the resulting high-dimensional posterior. MCMC might not be ideal for this, so I’m considering using normalizing flows in Pyro for posterior inference.

Is it feasible to call my R-based likelihood and prior from Python using a wrapper, such as rpy2, and use them in Pyro just for the Bayesian inference part? Specifically, I’m interested in whether Pyro’s normalizing flow methods can work with likelihood and prior values computed in R.

Thank you!

most inference algorithms require gradients and so you can’t blithely wrap computations that need gradients. you need to implement them in pytorch.