Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def is_symmetric(self):
"""
In the case of symmetric kernels, this method is overwritten in the
class SymmetricKernel, where it returns 'True', hence leaving the
here returned value 'False' for the asymmetric kernels.
"""
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.
@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)
ignored probability in the distribution corresponding to lower values
than the minimum in the array t.
"""
return np.nonzero(self(t).cumsum() *
(t[len(t) - 1] - t[0]) / (len(t) - 1) >= 0.5)[0].min()
def is_symmetric(self):
"""
In the case of symmetric kernels, this method is overwritten in the
class SymmetricKernel, where it returns 'True', hence leaving the
here returned value 'False' for the asymmetric kernels.
"""
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::
def _evaluate(self, t):
if not self.invert:
kernel = (t >= 0) * (1. / self._sigma_scaled.magnitude) *\
np.exp((-t / self._sigma_scaled).magnitude) / t.units
elif self.invert:
kernel = (t <= 0) * (1. / self._sigma_scaled.magnitude) *\
np.exp((t / self._sigma_scaled).magnitude) / t.units
return kernel
@inherit_docstring(Kernel.boundary_enclosing_area_fraction)
def boundary_enclosing_area_fraction(self, fraction):
self._check_fraction(fraction)
return -self.sigma * np.log(1.0 - fraction)
class AlphaKernel(Kernel):
"""
Class for alpha kernels
.. math::
K(t) = \\left\\{\\begin{array}{ll} (1 / \\tau^2)
\\ t\\ \\exp{(-t / \\tau)}, & t > 0 \\\\
0, & t \\leq 0 \\end{array} \\right.
with :math:`\\tau = \\sigma / \\sqrt{2}`.
For the alpha kernel an analytical expression for the boundary of the
integral as a function of the area under the alpha kernel function
cannot be given. Hence in this case the value of the boundary is
determined by kernel-approximating numerical integration, inherited
from the Kernel class.
@inherit_docstring(Kernel._evaluate)
def _evaluate(self, t):
return (3.0 / (4.0 * np.sqrt(5.0) * self._sigma_scaled)) * np.maximum(
0.0,
1 - (t / (np.sqrt(5.0) * self._sigma_scaled)).magnitude ** 2)
@inherit_docstring(Kernel._evaluate)
def _evaluate(self, t):
return (1 / (np.sqrt(2.0) * self._sigma_scaled)) * np.exp(
-(np.absolute(t) * np.sqrt(2.0) / self._sigma_scaled).magnitude)
@inherit_docstring(Kernel.boundary_enclosing_area_fraction)
def boundary_enclosing_area_fraction(self, fraction):
self._check_fraction(fraction)
return -self.sigma * np.log(1.0 - fraction) / np.sqrt(2.0)
# Potential further symmetric kernels from Wiki Kernels (statistics):
# Quartic (biweight), Triweight, Tricube, Cosine, Logistics, Silverman
class ExponentialKernel(Kernel):
"""
Class for exponential kernels
.. math::
K(t) = \\left\\{\\begin{array}{ll} (1 / \\tau) \\exp{(-t / \\tau)},
& t > 0 \\\\
0, & t \\leq 0 \\end{array} \\right.
with :math:`\\tau = \\sigma`.
Derived from:
"""
__doc__ += Kernel.__doc__
@property
def min_cutoff(self):