aloctavodia / BAP

Bayesian Analysis with Python (Second Edition)
https://www.amazon.com/dp/B07HHBCR9G
MIT License
649 stars 250 forks source link

Chapter 4 exercises - Question 6 #62

Closed bjonnh closed 4 years ago

bjonnh commented 4 years ago

The plot_hpd : az.plot_hpd(x_3[:,0], trace_3['bd'], color='k')

fails with :


LinAlgError Traceback (most recent call last)

in ----> 1 az.plot_hpd(x_3[:,0], trace_3['bd'], color='k') 2 3 plt.xlabel(x_n[0]) 4 plt.ylabel(x_n[1]); ~/Data/01-Software/03-Python/01-Anaconda3/lib/python3.7/site-packages/arviz/plots/hpdplot.py in plot_hpd(x, y, credible_interval, color, circular, smooth, smooth_kwargs, fill_kwargs, plot_kwargs, ax, backend, backend_kwargs, show) 98 x_data = np.linspace(x.min(), x.max(), 200) 99 hpd_interp = griddata(x, hpd_, x_data) --> 100 y_data = savgol_filter(hpd_interp, axis=0, **smooth_kwargs) 101 else: 102 idx = np.argsort(x) ~/Data/01-Software/03-Python/01-Anaconda3/lib/python3.7/site-packages/scipy/signal/_savitzky_golay.py in savgol_filter(x, window_length, polyorder, deriv, delta, axis, mode, cval) 346 # the last `window_length` elements. 347 y = convolve1d(x, coeffs, axis=axis, mode="constant") --> 348 _fit_edges_polyfit(x, window_length, polyorder, deriv, delta, axis, y) 349 else: 350 # Any mode other than 'interp' is passed on to ndimage.convolve1d. ~/Data/01-Software/03-Python/01-Anaconda3/lib/python3.7/site-packages/scipy/signal/_savitzky_golay.py in _fit_edges_polyfit(x, window_length, polyorder, deriv, delta, axis, y) 219 halflen = window_length // 2 220 _fit_edge(x, 0, window_length, 0, halflen, axis, --> 221 polyorder, deriv, delta, y) 222 n = x.shape[axis] 223 _fit_edge(x, n - window_length, n, n - halflen, n, axis, ~/Data/01-Software/03-Python/01-Anaconda3/lib/python3.7/site-packages/scipy/signal/_savitzky_golay.py in _fit_edge(x, window_start, window_stop, interp_start, interp_stop, axis, polyorder, deriv, delta, y) 189 # where '-1' is the same as in xx_edge. 190 poly_coeffs = np.polyfit(np.arange(0, window_stop - window_start), --> 191 xx_edge, polyorder) 192 193 if deriv > 0: <__array_function__ internals> in polyfit(*args, **kwargs) ~/Data/01-Software/03-Python/01-Anaconda3/lib/python3.7/site-packages/numpy/lib/polynomial.py in polyfit(x, y, deg, rcond, full, w, cov) 629 scale = NX.sqrt((lhs*lhs).sum(axis=0)) 630 lhs /= scale --> 631 c, resids, rank, s = lstsq(lhs, rhs, rcond) 632 c = (c.T/scale).T # broadcast scale coefficients 633 <__array_function__ internals> in lstsq(*args, **kwargs) ~/Data/01-Software/03-Python/01-Anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py in lstsq(a, b, rcond) 2266 # lapack can't handle n_rhs = 0 - so allocate the array one larger in that axis 2267 b = zeros(b.shape[:-2] + (m, n_rhs + 1), dtype=b.dtype) -> 2268 x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj) 2269 if m == 0: 2270 x[...] = 0 ~/Data/01-Software/03-Python/01-Anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py in _raise_linalgerror_lstsq(err, flag) 107 108 def _raise_linalgerror_lstsq(err, flag): --> 109 raise LinAlgError("SVD did not converge in Linear Least Squares") 110 111 def get_linalg_error_extobj(callback): LinAlgError: SVD did not converge in Linear Least Squares
aloctavodia commented 4 years ago

Hi, I am not able to reproduce the problem either. I tried with the version of arviz mentioned in the book and with the one from master, could you try updating arviz?

bjonnh commented 4 years ago

Not in the book, it is in the exercise notebooks of this repo. Arviz PyMC are the last in anaconda.

bjonnh commented 4 years ago

https://github.com/aloctavodia/BAP/blob/master/exercises/Chapter4.ipynb

aloctavodia commented 4 years ago

I am not able to reproduce this error, try installing the arviz version specified in the book or the one from master. pip install git+git://github.com/arviz-devs/arviz.git