Skip to content
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

'Beta' object is not iterable #3126

Closed
cpwang007 opened this issue Jul 29, 2018 · 4 comments
Closed

'Beta' object is not iterable #3126

cpwang007 opened this issue Jul 29, 2018 · 4 comments

Comments

@cpwang007
Copy link

@cpwang007 cpwang007 commented Jul 29, 2018

Beta object is not iterable.

Description of your problem

Please provide a minimal, self-contained, and reproducible example.

# setup model

with pm.Model() as model:
    a = pm.Uniform('a', lower=0, upper=15, shape=(2,))
    b = pm.Uniform('b', lower=0, upper=15, shape=(2,))
    components = pm.Beta.dist(alpha=a, beta=b, shape=(2,))
    w = pm.Dirichlet('w', a=np.array([1, 1]))
    like = pm.Mixture('like', w=w, comp_dists = components, observed=data)

Please provide the full traceback.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/mixture.py in _comp_modes(self)
    126         try:
--> 127             return tt.as_tensor_variable(self.comp_dists.mode)
    128         except AttributeError:

AttributeError: 'Beta' object has no attribute 'mode'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-205-2c90366e5a08> in <module>()
     10     w = pm.Dirichlet('w', a=np.array([1, 1]))
     11 
---> 12     like = pm.Mixture('like', w=w, comp_dists = components, observed=data)

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py in __new__(cls, name, *args, **kwargs)
     34                 raise TypeError("observed needs to be data but got: {}".format(type(data)))
     35             total_size = kwargs.pop('total_size', None)
---> 36             dist = cls.dist(*args, **kwargs)
     37             return model.Var(name, dist, data, total_size)
     38         else:

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py in dist(cls, *args, **kwargs)
     45     def dist(cls, *args, **kwargs):
     46         dist = object.__new__(cls)
---> 47         dist.__init__(*args, **kwargs)
     48         return dist
     49 

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/mixture.py in __init__(self, w, comp_dists, *args, **kwargs)
     91 
     92         try:
---> 93             comp_modes = self._comp_modes()
     94             comp_mode_logps = self.logp(comp_modes)
     95             self.mode = comp_modes[tt.argmax(w * comp_mode_logps, axis=-1)]

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/mixture.py in _comp_modes(self)
    128         except AttributeError:
    129             return tt.squeeze(tt.stack([comp_dist.mode
--> 130                                         for comp_dist in self.comp_dists],
    131                                        axis=1))
    132 

TypeError: 'Beta' object is not iterable

Please provide any additional information below.

Versions and main components

  • PyMC3 Version: 3.4.1
  • Theano Version: 1.0.2
  • Python Version: 3.6.5
  • Operating system: OS
  • How did you install PyMC3: (conda/pip) conda
@fonnesbeck

This comment has been minimized.

Copy link
Member

@fonnesbeck fonnesbeck commented Jul 29, 2018

I can confirm this on 3.5.

@junpenglao

This comment has been minimized.

Copy link
Member

@junpenglao junpenglao commented Jul 29, 2018

AttributeError: 'Beta' object has no attribute 'mode' I am surprised.

@junpenglao

This comment has been minimized.

Copy link
Member

@junpenglao junpenglao commented Jul 29, 2018

So since Beta doesnt have mode defined, when _comp_modes() is called, it throws a AttributeError. However, the exception handling in _comp_modes() was implemented with catching input comp_dist is a list, and attempt to compute the mode for each component.

@lucianopaz

This comment has been minimized.

Copy link
Contributor

@lucianopaz lucianopaz commented May 3, 2019

Mixture has changed a lot since this issue was posted. The original example no longer raises an exception, and samples correctly.

The only minor thing that could still be considered as open from this issue would be to implement the Beta distribution's mode. I'll close this now but if anyone wants to reopen it or edit it, feel free.

@lucianopaz lucianopaz closed this May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.