-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Base Model class for pymc3.models #1524
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
Comments
Here's my train of thought when I was designing the BEST object. I thought first about how the data should be structured in a Pandas dataframe in order to make the code most concise, and then designed it around that. From my limited experience, statisticians like it best when data are provided structured and cleaned, with one row representing one "observation", control or treatment alike. I think one thing that would be a necessity would be to pass in the data into the base Model class. I'm not sure what other keyword arguments would be necessary though. In the case of BEST, I needed to know what was the baseline "control", in order to compute other parameters, such as "Z-factors" or "effect sizes" (not yet implemented in my PR, wanted to start simple first). In the structured table that statisticians love, that's not going to be immediately evident without passing that in as well. I think the base class should definitely provide a Not so sure about the Here's a quick sketch of what it might look like: class Model(object):
def __init__(self, data):
super(Model, self).__init__()
self.data = data
...
def fit(self):
pm.sample_init(self.model)
def plot_posterior(self):
pass What do you have in mind for functionality that the base class would need? |
I think the essence is here. In constructor we give some input and description and construct the model itself. We should consider using from ..model import modelcontext
class UserModel(object):
def __init__(self, name):
# name should be used as prefix for
# all variables specified within a model
self.vars = OrderedDict()
self.name = name
@property
def model(self):
# Just shortcut
return modelcontext(None)
def _add_var(self, name, dist, data=None):
# Signature from pymc3.Model
var = self.model.Var('{}_{}'.format(self.name, name), dist=dist, data=data)
self.vars[name] = var
return var |
I like the direction this is taking. I worked on something similar before but mainly for caching model creation (if you want to run a model multiple times this is a serious overhead). Not sure we want to include it here but maybe also not rule out that it could one day be part of the API: https://gist.github.com/twiecki/972496588bf69fbfbd98ed6b01a3c8a8 |
I see such models as a building block for a big custom bayesian model, like layer in lasagne. That's the direction I see. |
That's interesting, hadn't thought about that. Can you give an example of what a model would look like with this API? |
Soon I'll write glm in that way using this api |
Closed by #1525 |
What do we need for base api? Good base class will help to maintain all models in the future. I think that lasagne like base class will be a good solution.
The text was updated successfully, but these errors were encountered: