Skip to content

Instantly share code, notes, and snippets.

@javiercorrea
Created July 25, 2015 03:54
Show Gist options
  • Save javiercorrea/9455389129c24baa9d64 to your computer and use it in GitHub Desktop.
Save javiercorrea/9455389129c24baa9d64 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aflaxman
Copy link

For me this produces a error earlier:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-9-560824d838b4> in <module>()
      9     p0 = np.ones(num_states, dtype=float) / num_states
     10     # No shape, so each state is a scalar tensor
---> 11     states = [pymc3.Categorical('s0', p = p0)]
     12     emissions = [pymc3.Categorical('z0',
     13                                    p = ifelse(eq(states[0], 0), E[0], ifelse(eq(states[0], 1), E[1], E[2])),

/homes/abie/anaconda/envs/testenv/lib/python2.7/site-packages/pymc3-3.0-py2.7.egg/pymc3/distributions/distribution.pyc in __new__(cls, name, *args, **kwargs)
     17             data = kwargs.pop('observed', None)
     18             dist = cls.dist(*args, **kwargs)
---> 19             return model.Var(name, dist, data)
     20         elif name is None:
     21             return object.__new__(cls) #for pickle

/homes/abie/anaconda/envs/testenv/lib/python2.7/site-packages/pymc3-3.0-py2.7.egg/pymc3/model.pyc in Var(self, name, dist, data)
    141         """
    142         if data is None:
--> 143             var = FreeRV(name=name, distribution=dist, model=self)
    144             self.free_RVs.append(var)
    145         else:

/homes/abie/anaconda/envs/testenv/lib/python2.7/site-packages/pymc3-3.0-py2.7.egg/pymc3/model.pyc in __init__(self, type, owner, index, name, distribution, model)
    351             self.tag.test_value = np.ones(
    352                 distribution.shape, distribution.dtype) * distribution.default()
--> 353             self.logp_elemwiset = distribution.logp(self)
    354             self.model = model
    355 

/homes/abie/anaconda/envs/testenv/lib/python2.7/site-packages/pymc3-3.0-py2.7.egg/pymc3/distributions/discrete.pyc in logp(self, value)
    287         k = self.k
    288 
--> 289         return bound(log(p[value]),
    290             value >= 0,
    291             value <= (k - 1),

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

@twiecki
Copy link

twiecki commented Jul 26, 2015

I would turn your variables into one vector rather than create the lists. Unfortunately, I hit this issue when I did that here: pymc-devs/pymc#792

@sshegheva
Copy link

I have a very similar model (actually the exact topology which made this example extremely helpful). I am having the same issue as outlined above, but I am not following the suggestion of @twiecki for creating a vector instead of the list.

I changed the lists to np.array everywhere where it is possible and it is not making any difference. Any other suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment