Closed tomwallis closed 1 month ago
Hi @tomwallis, sorry that we might not want to include that wrapper - mainly to keep numpyro at a right level of abstraction. But I agree that api will be very helpful for users.
Ok, thanks for the fast reply! I'll let you know if I end up creating a package for this purpose. Naming suggestions welcome.
Hi @fehiepsi, the initial release of numpyro-oop
is now out. You can find it here.
I just walked through the demo colab. The api is awesome! I would recommend using similar approach for other domains https://github.com/pyro-ppl/numpyro/issues/1361
Thanks!
TL;DR: would the numpyro devs be interested in a light OO API to Numpyro?
Hello,
In the context of working with different models, I found it unwieldy to handle all the variables that are associated with a model (e.g. the model function itself, the mcmc object, predictive samples, etc). Sampling, prediction, etc led to a lot of code repetition. Therefore I drafted a light object-oriented wrapper so that a user can more easily manage numpyro model objects.
The API looks something like:
where the
ModelOne
class contains a methodmodel
that defines the model. Sampling and prediction can then be performed with e.g.:prediction can be done with
Model comparison can be done with
and so on. You can see a more complete demo of the API here.
Currently, the user would be expected to write a new class that inherits from a
BaseNumpyroModel
, minimally defining a newmodel
method. An advantage of this approach is that the bulk of the repetitive sampling, prediction, etc code is hidden in the class. Additionally, all the variables and objects associated with a model are contained in the instance namespace (e.g. ofm1
), so that variable naming becomes a bit simpler and things can be found more easily. Yet the flexibility of writing the model directly is more-or-less maintained.I find this more convenient to work with. I was thinking about putting this helper wrapper into a new package, but if the numpyro devs are interested, maybe it makes sense to put it into numpyro directly?