Skip to content

Throws error AttributeError: module 'sampled.sampled' has no attribute 'Model' #6

@vr308

Description

@vr308

I have been using this deocrator to run the same generative model on datasets of different size but now it suddenly throws the error :

AttributeError: module 'sampled.sampled' has no attribute 'Model'

Can reproduce it with your example:

import numpy as np 
import pymc3 as pm
from sampled import sampled
import theano.tensor as tt
@sampled
def linear_model(X, y):
    shape = X.shape
    X = pm.Normal('X', mu=tt.mean(X, axis=0), sd=np.std(X, axis=0), shape=shape)
    coefs = pm.Normal('coefs', mu=tt.zeros(shape[1]), sd=tt.ones(shape[1]), shape=shape[1])
    pm.Normal('y', mu=tt.dot(X, coefs), sd=tt.ones(shape[0]), shape=shape[0])`
X = np.random.normal(size=(1000, 10))
w = np.random.normal(size=10)
y = X.dot(w) + np.random.normal(scale=0.1, size=1000)

with linear_model(X=X, y=y):
    sampled_coefs = pm.sample(draws=1000, tune=500)
Traceback (most recent call last):

  File "<ipython-input-9-2012d7efa2d1>", line 5, in <module>
    with linear_model(X=X, y=y):

  File "/home/vr308/anaconda3/lib/python3.6/site-packages/sampled/sampled.py", line 20, in wrapped_f
    with ObserverModel(observed) as model:

  File "/home/vr308/anaconda3/lib/python3.6/site-packages/pymc3/model.py", line 274, in __call__
    instance = cls.__new__(cls, *args, **kwargs)

  File "/home/vr308/anaconda3/lib/python3.6/site-packages/pymc3/model.py", line 739, in __new__
    instance._parent = cls.get_context(error_if_none=False)

  File "/home/vr308/anaconda3/lib/python3.6/site-packages/pymc3/model.py", line 213, in get_context
    candidate = cls.get_contexts()[idx] # type: Optional[T]

  File "/home/vr308/anaconda3/lib/python3.6/site-packages/pymc3/model.py", line 234, in get_contexts
    context_class = cls.context_class

  File "/home/vr308/anaconda3/lib/python3.6/site-packages/pymc3/model.py", line 260, in context_class
    cls._context_class = resolve_type(cls._context_class)

  File "/home/vr308/anaconda3/lib/python3.6/site-packages/pymc3/model.py", line 254, in resolve_type
    c = getattr(modules[cls.__module__], c)

AttributeError: module 'sampled.sampled' has no attribute 'Model'

pymc3 version 3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions