@@ -3656,12 +3656,13 @@ def stineman_interp(xi,x,y,yp=None):
3656
3656
1 / (dy1 + dy2 ),))
3657
3657
return yi
3658
3658
3659
+
3659
3660
class GaussianKDE (object ):
3660
3661
"""
3661
3662
Representation of a kernel-density estimate using Gaussian kernels.
3662
3663
3663
3664
Call signature::
3664
- kde = gaussian_kde (dataset, 'silverman')
3665
+ kde = GaussianKDE (dataset, bw_method= 'silverman')
3665
3666
3666
3667
Parameters
3667
3668
----------
@@ -3715,8 +3716,8 @@ def __init__(self, dataset, bw_method=None):
3715
3716
self .covariance_factor = self .scotts_factor
3716
3717
elif bw_method == 'silverman' :
3717
3718
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 ) ):
3720
3721
self ._bw_method = 'use constant'
3721
3722
self .covariance_factor = lambda : bw_method
3722
3723
elif callable (bw_method ):
@@ -3726,10 +3727,10 @@ def __init__(self, dataset, bw_method=None):
3726
3727
msg = "`bw_method` should be 'scott', 'silverman', a scalar " \
3727
3728
"or a callable."
3728
3729
raise ValueError (msg )
3729
-
3730
+
3730
3731
# Computes the covariance matrix for each Gaussian kernel using
3731
3732
# covariance_factor().
3732
-
3733
+
3733
3734
self .factor = self .covariance_factor ()
3734
3735
# Cache covariance and inverse covariance of the data
3735
3736
if not hasattr (self , '_data_inv_cov' ):
@@ -3780,14 +3781,9 @@ def evaluate(self, points):
3780
3781
3781
3782
dim , num_m = np .array (points ).shape
3782
3783
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 )
3791
3787
3792
3788
result = np .zeros ((num_m ,), dtype = np .float )
3793
3789
@@ -3812,6 +3808,7 @@ def evaluate(self, points):
3812
3808
3813
3809
__call__ = evaluate
3814
3810
3811
+
3815
3812
##################################################
3816
3813
# Code related to things in and around polygons
3817
3814
##################################################
0 commit comments