pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.68k stars 2.01k forks source link

Mixture model failure during sample_ppc #2346

Closed fonnesbeck closed 7 years ago

fonnesbeck commented 7 years ago

In the dependent density regression notebook, the posterior predictive checks cell fails on the mixture model:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-2fd0a2e33b32> in <module>()
      5 
      6 with model:
----> 7     pp_trace = pm.sample_ppc(trace, PP_SAMPLES, random_seed=SEED)

/Users/fonnescj/Repos/pymc3/pymc3/sampling.py in sample_ppc(trace, samples, model, vars, size, random_seed, progressbar)
    537             param = trace[idx]
    538             for var in vars:
--> 539                 vals = var.distribution.random(point=param, size=size)
    540                 ppc[var.name].append(vals)
    541     finally:

/Users/fonnescj/Repos/pymc3/pymc3/distributions/mixture.py in random(self, point, size, repeat)
    130         w_samples = generate_samples(random_choice,
    131                                      w=w,
--> 132                                      broadcast_shape=w.shape[:-1] or (1,),
    133                                      dist_shape=self.shape,
    134                                      size=size).squeeze()

AttributeError: 'list' object has no attribute 'shape'

Not sure how the weights end up in a list here.

junpenglao commented 7 years ago

Should be an easy fix - PR coming.

junpenglao commented 7 years ago

Done. It's a missing fix since last change of the function draw_value. (ref: see exchange in https://github.com/pymc-devs/pymc3/pull/2309/files)

fonnesbeck commented 7 years ago

Great, will test the notebook.

aseyboldt commented 7 years ago

Sorry, looks like I missed that one. @junpenglao There seems to be another one like that in transforms.py. Maybe introduce after the change.

junpenglao commented 7 years ago

@aseyboldt I dont see it in transforms.py? where?

aseyboldt commented 7 years ago

Sorry, I was wrong. I only looked at the grep output and missed the linebreak.

junpenglao commented 7 years ago

Yeah we should add a test case for mixture random.

fonnesbeck commented 7 years ago

Yep, fixed the issue. Closing.