Example for custom unnormalized likelihood and custom guid


I recently started using pyro. I am working on a problem where I only have un-normalized joint distribution and custom q (ie guide). I would like to maximize ELBO. Here is my question:

Is it possible to provide an example where we have only the unnormalized joint probability of the model? This can be done pymc3 by defining a distribution object and passing a function that computes logp. However, defining custom q is a bit restrictive. Defining custom guide in pyro is straightforward but according to this issue defining a custom probability for the model is not advised. Am I missing something:

If possible, could you please provide an example that one can pass logp and define a custom distribution?


That’s an old discussion thread more related to making it easier for users to define/test custom distribution classes. Since then, we have a much wider support for different distributions most of which have been moved upstream to torch.distributions. It should be straightforward to extend from the base distribution class (take a look at these pyro distributions, for example). I think that for as long as you have a valid log_prob (unnormalized is fine) method for the RVs in your model, and a valid sample method for the RVs in your guide, SVI should work fine.

as an example, we’ve done exactly this for the von mises distribution. notice that it only has a score method, so it only can be used in the model.