error plotting posterior_predictive plots and the Gelman-Rubin statistic

137 views
Skip to first unread message

AT

unread,
Jul 30, 2021, 9:55:34 AM7/30/21
to hddm-users

Hello HDDM users,

I am new to hddm and am working through the hddm tutorial posted on http://ski.clps.brown.edu/hddm_docs/tutorial_python.html on a Windows 10 Dell laptop. I am hoping someone can shed light on 2 different error messages that I am getting – one with the Gelman-Rubin statistic and the second when plotting posterior_predictive plots. 

The Gelman-Rubin Stat error:

The code works OK until I get to instantiate the model step. At this point I get a RuntimeWarning message, but the code was harmless and prints the expected output. I saw in a previous conversation that someone else had asked about the RuntimeWarning error and was told not to worry about the warning as it is harmless.

C:\Users\athapar\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\scipy\optimize\optimize.py:2116: RuntimeWarning: invalid value encountered in double_scalars

  tmp2 = (x - v) * (fx - fw)

I then run the code for the Gelman-Rubin Statistic. I again get the error message but at this point, the code behaves oddly - it goes through and completes the run with the following error message RuntimeWarning. But then instead of printing the output shown in the tutorial, it repeats the loop, and then it begins to repeat it again (see below - I actually halted the third run)


C:\Users\athapar\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\scipy\optimize\optimize.py:2116: RuntimeWarning: invalid value encountered in double_scalars tmp2 = (x - v) * (fx - fw)

[-----------------100%-----------------] 5000 of 5000 complete in 545.1 sec

C:\Users\athapar\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\scipy\optimize\optimize.py:2116: RuntimeWarning: invalid value encountered in double_scalars tmp2 = (x - v) * (fx - fw)

[-----------------100%-----------------] 5000 of 5000 complete in 537.2 sec

C:\Users\athapar\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\scipy\optimize\optimize.py:2116: RuntimeWarning: invalid value encountered in double_scalars tmp2 = (x - v) * (fx - fw)

[ 1% ] 95 of 5000 complete in 10.0 secHalting at iteration 94 of 5000


The plot_posterior_predictive()

The second issue is with the plot_posterior_predictive(m.plot_posterior_predictive(figsize=(14, 10))) function.

 

The full error message for the plot_posterior_predictive() is provided below. I get a plot which shows a red plot that looks as one would expect but a flat blue plot. I also tried this with a different dataset from the hddm package and again the plot_posterior_predictive() call resulted in the same error message and a plot that displays a red line and a flat blue line.

 

Thanks, Anjali

 

C:\Users\athapar\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\kabuki\analyze.py:556: MatplotlibDeprecationWarning: Passing non-integers as three-element position specification is deprecated since 3.3 and will be removed two minor releases later.   ax = fig.add_subplot(np.ceil(nrows), columns, subj_i+1)

 

AttributeError                            Traceback (most recent call last)<ipython-input-34-916850d95b91> in <module>----> 1 m.plot_posterior_predictive(figsize=(14, 10)) ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\hddm\models\base.py in plot_posterior_predictive(self, *args, **kwargs)    766         if 'value_range' not in kwargs:    767             kwargs['value_range'] = np.linspace(-5, 5, 100)--> 768         kabuki.analyze.plot_posterior_predictive(self, *args, **kwargs)    769     770     def plot_posterior_quantiles(self, *args, **kwargs): ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\kabuki\analyze.py in plot_posterior_predictive(model, plot_func, required_method, columns, save, path, figsize, format, num_subjs, **kwargs)    558                 ax.set_title(str(bottom_node['subj_idx']))    559 --> 560             plot_func(bottom_node['node'], ax, **kwargs)    561     562             if num_subjs is not None and i >= num_subjs: ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\kabuki\analyze.py in _plot_posterior_pdf_node(bottom_node, axis, value_range, samples, bins)    478         axis.hist(bottom_node.value.values, normed=True, color='r',    479                   range=(value_range[0], value_range[-1]), label='data',--> 480                   bins=bins, histtype='step', lw=2.)    481     482     axis.set_ylim(bottom=0) # Likelihood and histogram can only be positive ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)   1445     def inner(ax, *args, data=None, **kwargs):   1446         if data is None:-> 1447             return func(ax, *map(sanitize_sequence, args), **kwargs)   1448    1449         bound = new_sig.bind(ax, *args, **kwargs) ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\matplotlib\axes\_axes.py in hist(self, x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)   6813             if patch:   6814                 p = patch[0]-> 6815                 p.update(kwargs)   6816                 if lbl is not None:   6817                     p.set_label(lbl) ~\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\matplotlib\artist.py in update(self, props)    994                     func = getattr(self, f"set_{k}", None)    995                     if not callable(func):--> 996                         raise AttributeError(f"{type(self).__name__!r} object "    997                                              f"has no property {k!r}")    998                     ret.append(func(v)) AttributeError: 'Polygon' object has no property 'normed'

Alexander Fengler

unread,
Aug 30, 2021, 3:33:53 PM8/30/21
to hddm-users
Hi Anjali,

could you include the code you ran into your question?
So far I don't have an idea what could be wrong.

Best,
Alex

Mohamed Sherif

unread,
Sep 9, 2021, 5:04:56 PM9/9/21
to hddm-users
Hi Anjali,

For plot_posterior_predictive(), I came across the same error. The solution for me was to change 'normed' (without quotes) in line 478 of the file:
~/anaconda3/envs/pyHDDM/lib/python3.6/site-packages/kabuki/analyze.py
to "density' (without single quotes).

Seems that the error and solution were posted here before as well:

Hope this helps.

Mohamed.

Ying

unread,
Oct 5, 2021, 2:53:54 PM10/5/21
to hddm-users
I'm having the same issue, and I tried changing the file from normed to density as per Mohamed's suggestion, but I still get the same error.

Was there another file that I should also change? 

Thank you so much!

Reply all
Reply to author
Forward
0 new messages