|
|
@ -325,6 +325,7 @@ class _KernelMulti(_Kernel):
|
|
|
|
p=3; Multivariate Tri-weight Kernel
|
|
|
|
p=3; Multivariate Tri-weight Kernel
|
|
|
|
p=4; Multivariate Four-weight Kernel
|
|
|
|
p=4; Multivariate Four-weight Kernel
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, r=1.0, p=1, stats=None, name=''):
|
|
|
|
def __init__(self, r=1.0, p=1, stats=None, name=''):
|
|
|
|
self.p = p
|
|
|
|
self.p = p
|
|
|
|
super(_KernelMulti, self).__init__(r, stats, name)
|
|
|
|
super(_KernelMulti, self).__init__(r, stats, name)
|
|
|
@ -342,6 +343,7 @@ class _KernelMulti(_Kernel):
|
|
|
|
x2 = x ** 2
|
|
|
|
x2 = x ** 2
|
|
|
|
return ((1.0 - x2.sum(axis=0) / r ** 2).clip(min=0.0)) ** p
|
|
|
|
return ((1.0 - x2.sum(axis=0) / r ** 2).clip(min=0.0)) ** p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkernel_epanechnikov = _KernelMulti(p=1, stats=_stats_epan,
|
|
|
|
mkernel_epanechnikov = _KernelMulti(p=1, stats=_stats_epan,
|
|
|
|
name='epanechnikov')
|
|
|
|
name='epanechnikov')
|
|
|
|
mkernel_biweight = _KernelMulti(p=2, stats=_stats_biwe, name='biweight')
|
|
|
|
mkernel_biweight = _KernelMulti(p=2, stats=_stats_biwe, name='biweight')
|
|
|
@ -356,6 +358,7 @@ class _KernelProduct(_KernelMulti):
|
|
|
|
p=3; 1D product Tri-weight Kernel
|
|
|
|
p=3; 1D product Tri-weight Kernel
|
|
|
|
p=4; 1D product Four-weight Kernel
|
|
|
|
p=4; 1D product Four-weight Kernel
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def norm_factor(self, d=1, n=None):
|
|
|
|
def norm_factor(self, d=1, n=None):
|
|
|
|
r = self.r
|
|
|
|
r = self.r
|
|
|
|
p = self.p
|
|
|
|
p = self.p
|
|
|
@ -368,6 +371,7 @@ class _KernelProduct(_KernelMulti):
|
|
|
|
pdf = (1 - (x / r) ** 2).clip(min=0.0) ** self.p
|
|
|
|
pdf = (1 - (x / r) ** 2).clip(min=0.0) ** self.p
|
|
|
|
return pdf.prod(axis=0)
|
|
|
|
return pdf.prod(axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkernel_p1epanechnikov = _KernelProduct(p=1, stats=_stats_epan,
|
|
|
|
mkernel_p1epanechnikov = _KernelProduct(p=1, stats=_stats_epan,
|
|
|
|
name='p1epanechnikov')
|
|
|
|
name='p1epanechnikov')
|
|
|
|
mkernel_p1biweight = _KernelProduct(p=2, stats=_stats_biwe, name='p1biweight')
|
|
|
|
mkernel_p1biweight = _KernelProduct(p=2, stats=_stats_biwe, name='p1biweight')
|
|
|
@ -383,6 +387,8 @@ class _KernelRectangular(_Kernel):
|
|
|
|
def norm_factor(self, d=1, n=None):
|
|
|
|
def norm_factor(self, d=1, n=None):
|
|
|
|
r = self.r
|
|
|
|
r = self.r
|
|
|
|
return (2 * r) ** d
|
|
|
|
return (2 * r) ** d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkernel_rectangular = _KernelRectangular(stats=_stats_rect)
|
|
|
|
mkernel_rectangular = _KernelRectangular(stats=_stats_rect)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -391,6 +397,8 @@ class _KernelTriangular(_Kernel):
|
|
|
|
def _kernel(self, x):
|
|
|
|
def _kernel(self, x):
|
|
|
|
pdf = (1 - np.abs(x)).clip(min=0.0)
|
|
|
|
pdf = (1 - np.abs(x)).clip(min=0.0)
|
|
|
|
return pdf.prod(axis=0)
|
|
|
|
return pdf.prod(axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkernel_triangular = _KernelTriangular(stats=_stats_tria)
|
|
|
|
mkernel_triangular = _KernelTriangular(stats=_stats_tria)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -425,6 +433,7 @@ class _KernelGaussian(_Kernel):
|
|
|
|
) / (sqrt(pi) * (2 * sigma) ** (r + 1))
|
|
|
|
) / (sqrt(pi) * (2 * sigma) ** (r + 1))
|
|
|
|
return psi_r
|
|
|
|
return psi_r
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkernel_gaussian = _KernelGaussian(r=4.0, stats=_stats_gaus)
|
|
|
|
mkernel_gaussian = _KernelGaussian(r=4.0, stats=_stats_gaus)
|
|
|
|
_GAUSS_KERNEL = mkernel_gaussian
|
|
|
|
_GAUSS_KERNEL = mkernel_gaussian
|
|
|
|
|
|
|
|
|
|
|
@ -437,6 +446,8 @@ class _KernelLaplace(_Kernel):
|
|
|
|
|
|
|
|
|
|
|
|
def norm_factor(self, d=1, n=None):
|
|
|
|
def norm_factor(self, d=1, n=None):
|
|
|
|
return 2 ** d
|
|
|
|
return 2 ** d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkernel_laplace = _KernelLaplace(r=7.0, stats=_stats_lapl)
|
|
|
|
mkernel_laplace = _KernelLaplace(r=7.0, stats=_stats_lapl)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -445,6 +456,8 @@ class _KernelLogistic(_Kernel):
|
|
|
|
def _kernel(self, x):
|
|
|
|
def _kernel(self, x):
|
|
|
|
s = exp(x)
|
|
|
|
s = exp(x)
|
|
|
|
return np.prod(s / (s + 1) ** 2, axis=0)
|
|
|
|
return np.prod(s / (s + 1) ** 2, axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mkernel_logistic = _KernelLogistic(r=7.0, stats=_stats_logi)
|
|
|
|
mkernel_logistic = _KernelLogistic(r=7.0, stats=_stats_logi)
|
|
|
|
|
|
|
|
|
|
|
|
_MKERNEL_DICT = dict(
|
|
|
|
_MKERNEL_DICT = dict(
|
|
|
|