Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return False
class SymmetricKernel(Kernel):
"""
Base class for symmetric kernels.
Derived from:
"""
__doc__ += Kernel.__doc__
def is_symmetric(self):
return True
class RectangularKernel(SymmetricKernel):
"""
Class for rectangular kernels
.. math::
K(t) = \\left\\{\\begin{array}{ll} \\frac{1}{2 \\tau}, & |t| < \\tau \\\\
0, & |t| \\geq \\tau \\end{array} \\right.
with :math:`\\tau = \\sqrt{3} \\sigma` corresponding to the half width
of the kernel.
Besides the standard deviation `sigma`, for consistency of interfaces the
parameter `invert` needed for asymmetric kernels also exists without
having any effect in the case of symmetric kernels.
Derived from:
"""
return min_cutoff
@inherit_docstring(Kernel._evaluate)
def _evaluate(self, t):
return (1.0 / (np.sqrt(6.0) * self._sigma_scaled)) * np.maximum(
0.0,
(1.0 - (np.absolute(t) /
(np.sqrt(6.0) * self._sigma_scaled)).magnitude))
@inherit_docstring(Kernel.boundary_enclosing_area_fraction)
def boundary_enclosing_area_fraction(self, fraction):
self._check_fraction(fraction)
return np.sqrt(6.0) * self.sigma * (1 - np.sqrt(1 - fraction))
class EpanechnikovLikeKernel(SymmetricKernel):
"""
Class for epanechnikov-like kernels
.. math::
K(t) = \\left\\{\\begin{array}{ll} (3 /(4 d)) (1 - (t / d)^2),
& |t| < d \\\\
0, & |t| \\geq d \\end{array} \\right.
with :math:`d = \\sqrt{5} \\sigma` being the half width of the kernel.
The Epanechnikov kernel under full consideration of its axioms has a half
width of :math:`\\sqrt{5}`. Ignoring one axiom also the respective kernel
with half width = 1 can be called Epanechnikov kernel.
( https://de.wikipedia.org/wiki/Epanechnikov-Kern )
However, arbitrary width of this type of kernel is here preferred to be
called 'Epanechnikov-like' kernel.
self._check_fraction(fraction)
# Python's complex-operator cannot handle quantities, hence the
# following construction on quantities is necessary:
Delta_0 = complex(1.0 / (5.0 * self.sigma.magnitude**2), 0) / \
self.sigma.units**2
Delta_1 = complex(2.0 * np.sqrt(5.0) * fraction /
(25.0 * self.sigma.magnitude**3), 0) / \
self.sigma.units**3
C = ((Delta_1 + (Delta_1**2.0 - 4.0 * Delta_0**3.0)**(1.0 / 2.0)) /
2.0)**(1.0 / 3.0)
u_3 = complex(-1.0 / 2.0, -np.sqrt(3.0) / 2.0)
b = -5.0 * self.sigma**2 * (u_3 * C + Delta_0 / (u_3 * C))
return b.real
class GaussianKernel(SymmetricKernel):
"""
Class for gaussian kernels
.. math::
K(t) = (\\frac{1}{\\sigma \\sqrt{2 \\pi}})
\\exp(-\\frac{t^2}{2 \\sigma^2})
with :math:`\\sigma` being the standard deviation.
Besides the standard deviation `sigma`, for consistency of interfaces the
parameter `invert` needed for asymmetric kernels also exists without
having any effect in the case of symmetric kernels.
Derived from:
"""
__doc__ += SymmetricKernel.__doc__
def min_cutoff(self):
min_cutoff = np.sqrt(3.0)
return min_cutoff
@inherit_docstring(Kernel._evaluate)
def _evaluate(self, t):
return (0.5 / (np.sqrt(3.0) * self._sigma_scaled)) * \
(np.absolute(t) < np.sqrt(3.0) * self._sigma_scaled)
@inherit_docstring(Kernel.boundary_enclosing_area_fraction)
def boundary_enclosing_area_fraction(self, fraction):
self._check_fraction(fraction)
return np.sqrt(3.0) * self.sigma * fraction
class TriangularKernel(SymmetricKernel):
"""
Class for triangular kernels
.. math::
K(t) = \\left\\{ \\begin{array}{ll} \\frac{1}{\\tau} (1
- \\frac{|t|}{\\tau}), & |t| < \\tau \\\\
0, & |t| \\geq \\tau \\end{array} \\right.
with :math:`\\tau = \\sqrt{6} \\sigma` corresponding to the half width of
the kernel.
Besides the standard deviation `sigma`, for consistency of interfaces the
parameter `invert` needed for asymmetric kernels also exists without
having any effect in the case of symmetric kernels.
Derived from:
def min_cutoff(self):
min_cutoff = 3.0
return min_cutoff
@inherit_docstring(Kernel._evaluate)
def _evaluate(self, t):
return (1.0 / (np.sqrt(2.0 * np.pi) * self._sigma_scaled)) * np.exp(
-0.5 * (t / self._sigma_scaled).magnitude ** 2)
@inherit_docstring(Kernel.boundary_enclosing_area_fraction)
def boundary_enclosing_area_fraction(self, fraction):
self._check_fraction(fraction)
return self.sigma * np.sqrt(2.0) * scipy.special.erfinv(fraction)
class LaplacianKernel(SymmetricKernel):
"""
Class for laplacian kernels
.. math::
K(t) = \\frac{1}{2 \\tau} \\exp(-|\\frac{t}{\\tau}|)
with :math:`\\tau = \\sigma / \\sqrt{2}`.
Besides the standard deviation `sigma`, for consistency of interfaces the
parameter `invert` needed for asymmetric kernels also exists without
having any effect in the case of symmetric kernels.
Derived from:
"""
__doc__ += SymmetricKernel.__doc__
Class for rectangular kernels
.. math::
K(t) = \\left\\{\\begin{array}{ll} \\frac{1}{2 \\tau}, & |t| < \\tau \\\\
0, & |t| \\geq \\tau \\end{array} \\right.
with :math:`\\tau = \\sqrt{3} \\sigma` corresponding to the half width
of the kernel.
Besides the standard deviation `sigma`, for consistency of interfaces the
parameter `invert` needed for asymmetric kernels also exists without
having any effect in the case of symmetric kernels.
Derived from:
"""
__doc__ += SymmetricKernel.__doc__
@property
def min_cutoff(self):
min_cutoff = np.sqrt(3.0)
return min_cutoff
@inherit_docstring(Kernel._evaluate)
def _evaluate(self, t):
return (0.5 / (np.sqrt(3.0) * self._sigma_scaled)) * \
(np.absolute(t) < np.sqrt(3.0) * self._sigma_scaled)
@inherit_docstring(Kernel.boundary_enclosing_area_fraction)
def boundary_enclosing_area_fraction(self, fraction):
self._check_fraction(fraction)
return np.sqrt(3.0) * self.sigma * fraction