-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option for a functional API? #84
Comments
I like it. One key question is if the model class can be initialized twice as we currently do with the function. We have to call it twice in different contexts currently, once to create RVs and gather the tensors, and then once to create the logp tensor with inputs from step 1. |
@adamboche Any more thoughts on this? |
@twiecki Sorry for the delay; I'm hoping for a moment to experiment with it this week. |
I like the idea of separating model and data in this way. Would make applying the model to batches of datasets (e.g. to simulations for power estimations) much more convenient. |
I started trying out some basic ideas but it'll require more thought and experimentation -- nothing I have is usable and I wouldn't recommend implementing their current incarnation. In case anyone wants to read along, my code is available. Some things I like so far:
On the other hand, there is still a bit more magic involved than I'd like, and there's an issue of how to represent variables that depend on other variables. |
that looks quite interesting, is this functional or just pseudo code? |
Just looked a bit over the code base, looks really nice. Unless I missed it, the key missing piece is construction of a tensor-in-tensor-out logp function. |
Closing due to inactivity. |
Curious if this ever went anywhere? I see no linked issues but I'd not be surprised if it was picked up elsewhere |
@Padarn pymc4 is no more, check out pymc 5: https://github.com/pymc-devs/pymc |
Thanks @twiecki. I had seen that but couldn't find discussion on this topic there. Would you suggest opening an issue to discuss in the pymc repo? |
I'd be curious what use-case you're after. |
Sure. Nothing very specific, I just thought the proposal here was quite nice and made the API easier to understand. Teaching people about the context manager API has been a hurdle in getting people to work on pymc code in my team. |
Curious, it hasn't been a problem in my experience, but I also don't go into detail of what it does. In any case, we probably won't provide an alternative API in PyMC. |
Got it, totally reasonable. Thanks for your responses. |
@Padarn https://www.pymc.io/projects/docs/en/latest/api/model/transform.html is kind of like that, allows to use immutable models in functional way |
This exists for PyMC 5.x here: https://github.com/pymc-devs/pymc-experimental/blob/main/pymc_experimental/model/model_api.py#L6 |
Very cool, thanks @twiecki |
Hello! I'm excited to see all the cool ideas going on in the new PyMC, and I'm looking forward to using it for real. I've been following the development a little, and had an idea I wanted to run by you. I'm still new to PyMC, so please correct me if I get anything wrong.
One of the distinctive features of PyMC is its usage of context managers for building models, like this:
This kind of API is powerful in that it allows users to transparently access the sampling backend without extra work, and it makes common workflows really quick and easy. The decorator-based
@pm.model
API has similar advantages. The developer guide explains the power and flexibility that comes out of this design.The design also has some side effects:
I've been wondering about some possible API designs. Some of them may have been discussed and rejected already; please forgive me if I'm being redundant.
One idea that might be familiar to Python developers might be using a class per model, something like this:
I'm not 100% sure that it can do everything PyMC needs, but, from my (possibly naive) perspective, having an option like this might have some benefits:
There's a lot to explore in this design space. If this seems interesting to people, I'm happy to discuss or try out some implementation ideas, to see if something like this could be possible, and if it'd be nice. I'd love to hear your thoughts! 🙂
The text was updated successfully, but these errors were encountered: