Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca7d605

Browse files
khchansolvents
authored andcommitted
Fixed kde for invalid bw_methods, misc test formatting.
Some course related tests were added. These are removed later.
1 parent 39c66a9 commit ca7d605

35 files changed

+10519
-86
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ def tk_window_focus():
13601360
'matplotlib.tests.test_tightlayout',
13611361
'matplotlib.tests.test_transforms',
13621362
'matplotlib.tests.test_triangulation',
1363+
'matplotlib.tests.test_vpcoverage',
13631364
]
13641365

13651366

lib/matplotlib/mlab.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,12 +3656,13 @@ def stineman_interp(xi,x,y,yp=None):
36563656
1/(dy1+dy2),))
36573657
return yi
36583658

3659+
36593660
class GaussianKDE(object):
36603661
"""
36613662
Representation of a kernel-density estimate using Gaussian kernels.
36623663
36633664
Call signature::
3664-
kde = gaussian_kde(dataset, 'silverman')
3665+
kde = GaussianKDE(dataset, bw_method='silverman')
36653666
36663667
Parameters
36673668
----------
@@ -3715,8 +3716,8 @@ def __init__(self, dataset, bw_method=None):
37153716
self.covariance_factor = self.scotts_factor
37163717
elif bw_method == 'silverman':
37173718
self.covariance_factor = self.silverman_factor
3718-
elif np.isscalar(bw_method):
3719-
if not isinstance(bw_method, six.string_types):
3719+
elif (np.isscalar(bw_method) and not
3720+
isinstance(bw_method, six.string_types)):
37203721
self._bw_method = 'use constant'
37213722
self.covariance_factor = lambda: bw_method
37223723
elif callable(bw_method):
@@ -3726,10 +3727,10 @@ def __init__(self, dataset, bw_method=None):
37263727
msg = "`bw_method` should be 'scott', 'silverman', a scalar " \
37273728
"or a callable."
37283729
raise ValueError(msg)
3729-
3730+
37303731
# Computes the covariance matrix for each Gaussian kernel using
37313732
# covariance_factor().
3732-
3733+
37333734
self.factor = self.covariance_factor()
37343735
# Cache covariance and inverse covariance of the data
37353736
if not hasattr(self, '_data_inv_cov'):
@@ -3780,14 +3781,9 @@ def evaluate(self, points):
37803781

37813782
dim, num_m = np.array(points).shape
37823783
if dim != self.dim:
3783-
if dim == 1 and num_m == self.dim:
3784-
# points was passed in as a row vector
3785-
points = np.reshape(points, (self.dim, 1))
3786-
num_m = 1
3787-
else:
3788-
msg = "points have dimension %s, dataset has dimension %s" % (
3789-
dim, self.dim)
3790-
raise ValueError(msg)
3784+
msg = "points have dimension %s, dataset has dimension %s" % (
3785+
dim, self.dim)
3786+
raise ValueError(msg)
37913787

37923788
result = np.zeros((num_m,), dtype=np.float)
37933789

@@ -3812,6 +3808,7 @@ def evaluate(self, points):
38123808

38133809
__call__ = evaluate
38143810

3811+
38153812
##################################################
38163813
# Code related to things in and around polygons
38173814
##################################################
Binary file not shown.
Loading

0 commit comments

Comments
 (0)