Closed realzehuali closed 2 years ago
Thanks for the issue. It looks like this is not an issue from quasildr but a problem of your seaborn version not being compatible with the scipy version. Can you try whether upgrading seaborn and scipy to the most recent version solve the issue? If not, you can try installing scipy==1.4.1 and seaborn==0.10.0 which were used for testing the code. Can you post your current seaborn and scipy version and whether one of these solutions solves your issue here?
Thanks for this tool! My boss recently asked to me test quasildr on our data. When I was testing quasildr on your example data using jupyter notebok "Tutorial for further topics about density ridge analysis", I run into this error when running the code bar:
from matplotlib import pyplot as plt %matplotlib inline
h, , g, , msu = s._nlocal_inv_cov(grid) eigvals, eigvecs = np.linalg.eigh(-h) eigvals = -eigvals
h2 = eigvecs.copy() h2[:,:,0]=0 from numpy.core.umath_tests import matrix_multiply g2 = matrix_multiply(matrix_multiply(h2, h2.transpose((0, 2, 1))), g[:, :, np.newaxis])[:,:,0]
import seaborn as sns sns.set_style("whitegrid") fig = plt.figure(figsize=(10,10)) sns.kdeplot(data[:,0],data[:,1],bw=(0.35,0.35),cmap='Blues',n_levels=10,shade=True, shade_lowest=False) plt.quiver(grid[:,0], grid[:,1],g[:,0],g[:,1],color='#000000',alpha=0.1,scale=7) plt.quiver(grid[:,0], grid[:,1],g2[:,0],g2[:,1],color='#000000',scale=7) plt.quiver(grid[:,0], grid[:,1],eigvecs[:,0,0],eigvecs[:,1,0], headlength=0, color='#222222', pivot='middle',headaxislength=0) plt.scatter(allshiftedx_grid[:,-1],allshiftedy_grid[:,-1],color='steelblue',s=15)
Here is the error message: ValueError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_13492/1680992253.py in
14 sns.set_style("whitegrid")
15 fig = plt.figure(figsize=(10,10))
---> 16 sns.kdeplot(data[:,0],data[:,1],bw=(0.35,0.35),cmap='Blues',n_levels=10,shade=True, shade_lowest=False)
17 plt.quiver(grid[:,0], grid[:,1],g[:,0],g[:,1],color='#000000',alpha=0.1,scale=7)
18 plt.quiver(grid[:,0], grid[:,1],g2[:,0],g2[:,1],color='#000000',scale=7)
~\Envs\quasildr\lib\site-packages\seaborn_decorators.py in inner_f(*args, kwargs) 44 ) 45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)}) ---> 46 return f(kwargs) 47 return inner_f 48
~\Envs\quasildr\lib\site-packages\seaborn\distributions.py in kdeplot(x, y, shade, vertical, kernel, bw, gridsize, cut, clip, legend, cumulative, shade_lowest, cbar, cbar_ax, cbar_kws, ax, weights, hue, palette, hue_order, hue_norm, multiple, common_norm, common_grid, levels, thresh, bw_method, bw_adjust, log_scale, color, fill, data, data2, warn_singular, kwargs) 1793 cbar_kws=cbar_kws, 1794 estimate_kws=estimate_kws, -> 1795 kwargs, 1796 ) 1797
~\Envs\quasildr\lib\site-packages\seaborn\distributions.py in plot_bivariate_density(self, common_norm, fill, levels, thresh, color, legend, cbar, warn_singular, cbar_ax, cbar_kws, estimate_kws, *contour_kws) 1109 # Estimate the density of observations at this level 1110 observations = observations["x"], observations["y"] -> 1111 density, support = estimator(observations, weights=weights) 1112 1113 # Transform the support grid back to the original scale
~\Envs\quasildr\lib\site-packages\seaborn_statistics.py in call(self, x1, x2, weights) 187 return self._eval_univariate(x1, weights) 188 else: --> 189 return self._eval_bivariate(x1, x2, weights) 190 191
~\Envs\quasildr\lib\site-packages\seaborn_statistics.py in _eval_bivariate(self, x1, x2, weights) 162 support = self.support 163 if support is None: --> 164 support = self.define_support(x1, x2, cache=False) 165 166 kde = self._fit([x1, x2], weights)
~\Envs\quasildr\lib\site-packages\seaborn_statistics.py in define_support(self, x1, x2, weights, cache) 119 support = self._define_support_univariate(x1, weights) 120 else: --> 121 support = self._define_support_bivariate(x1, x2, weights) 122 123 if cache:
~\Envs\quasildr\lib\site-packages\seaborn_statistics.py in _define_support_bivariate(self, x1, x2, weights) 102 clip = (clip, clip) 103 --> 104 kde = self._fit([x1, x2], weights) 105 bw = np.sqrt(np.diag(kde.covariance).squeeze()) 106
~\Envs\quasildr\lib\site-packages\seaborn_statistics.py in _fit(self, fit_data, weights) 135 fit_kws["weights"] = weights 136 --> 137 kde = stats.gaussian_kde(fit_data, *fit_kws) 138 kde.set_bandwidth(kde.factor self.bw_adjust) 139
~\Envs\quasildr\lib\site-packages\scipy\stats\kde.py in init(self, dataset, bw_method, weights) 204 self._neff = 1/sum(self._weights**2) 205 --> 206 self.set_bandwidth(bw_method=bw_method) 207 208 def evaluate(self, points):
~\Envs\quasildr\lib\site-packages\scipy\stats\kde.py in set_bandwidth(self, bw_method) 550 msg = "
bw_method
should be 'scott', 'silverman', a scalar " \ 551 "or a callable." --> 552 raise ValueError(msg) 553 554 self._compute_covariance()ValueError:
bw_method
should be 'scott', 'silverman', a scalar or a callable.Any suggestions would be helpful! Thanks!