Skip to main content
`Ctrl`+`K`

# Kernel

Kernels for filtering, smoothing and stochastics simulations.

An example of Kernel simplification with an Gaussian Filter:

    kernel = GaussianKernel(3)
    trace.operate(Operator.FILTER, "x", kernel, "x_filtered")
    trace.operate(Operator.FILTER, "y", kernel, "y_filtered")
    trace.plot(append = False, sym='g-', label='original track')
    plt.plot(trace.getAnalyticalFeature("x_filtered"), trace.getAnalyticalFeature("y_filtered"),
                   'b-', label='simplify:gaussian filter')
    plt.legend()

Figure 1: Simplification with a gaussian kernel filter

class tracklib.core.Kernel.Kernel(function, support)

  Generic kernel class

  __filter_boundary = False

    TODO

  __kernel_function = None

    TODO

  __support = None

    TODO

  __init__(function, support)

    Kernel constructor

    Parameters

      - function (`Callable`[[`float`], `float`]) – Kernel function

      - support (`float`) – Kernel support

  setFilterBoundary(bool)

    Set filter boundary

    Parameters

      bool (`bool`) – TODO

  filterBoundary()

    Return the filterBoundary parameter value

    Return type

      `bool`

    Returns

      filterBoundary value

  setFunction(function)

    Set the function used by Kernel

    Parameters

      function (`Callable`[[`float`], `float`]) – A kernel function

  getFunction()

    Return the function used by the kernel

    Return type

      `Callable`[[`float`], `float`]

    Returns

      A kernel function

  plot(append=False)

    Plot the kernel

    Parameters

      append (`bool`) – TODO

  evaluate(x)

    Evaluate the kernel for a given value

    Parameters

      x (`float`) – Value to evaluate

    Retun

      Kernel value

    Return type

      `float`

  toSlidingWindow()

    Transform the kernel in a sliding windows

    Return type

      `list`[`int`]

    Returns

      A sliding windows

class tracklib.core.Kernel.DiracKernel

  Define a DiracKernel

  __init__()

    Constructor of a dirac kernel

  __str__()

    Print the kernel type

    Return type

      `str`

class tracklib.core.Kernel.UniformKernel(size)

  Define a unifomr kernel

  __init__(size)

    Constructor of a Uniform kernel

    The kernel’s function is :

    \[f(x)=\frac{1}{2 \cdot s}\]

    For a \(\|x\| \leq 1\) support

    Parameters

      size (`float`) – The size (\(s\)) of the kernel

  __str__()

    Print the kernel type

    Return type

      `str`

class tracklib.core.Kernel.TriangularKernel(size)

  Define a triangular kernel

  __init__(size)

    Constructor of triangular Kernel

    The kernel’s function is :

    \[f(x)= \frac{s - \|x\|}{s^2}\]

    For a \(\|x\| \leq 1\) support

    Parameters

      size (`float`) – The size (\(s\)) of the kernel

  __str__()

    Print the kernel type

    Return type

      `str`

class tracklib.core.Kernel.GaussianKernel(sigma)

  Define a Gaussian Kernel

  __init__(sigma)

    Constructor of Gaussian kernel

    The kernel’s function is :

    \[f(x)=\frac{e^{-0.5 \cdot \left(x/\sigma \right)^2}} {\sigma \cdot \sqrt{2 \cdot \pi}}\]
    Parameters

      sigma (`float`) – The sigma value (\(\sigma\)) for the kernel

  __str__()

    Print the kernel type

    Return type

      `str`

class tracklib.core.Kernel.ExponentialKernel(sigma)

  Define an Exponential Kernel

  __init__(sigma)

    Constructor of Exponential Kernel

    The Kernel function is:

    > \[f(x) = \frac{e^{-\|x\| / \sigma}}{2 \cdot \sigma}\]

    Parameters

      sigma (`float`) – The sigma value (\(\sigma\)) for the kernel

  __str__()

    Print the kernel type

    Return type

      `str`

class tracklib.core.Kernel.EpanechnikovKernel(size)

  Define a Epanechnikov Kernel

  __init__(size)

    Constructor of a Epanechnikov Kernel

    The kernel function is :

    > \[f(x) = \frac{3}{4} \cdot \left(1 - \left( \frac{x}{s} \right) ^2 \right) \cdot \frac{1}{s}\]

    For a \(\|x\| \leq 1\) support

    Parameters

      size (`float`) – The size parameter (\(s\)) for the kernel

  __str__()

    Print the kernel type

    Return type

      `str`

class tracklib.core.Kernel.SincKernel(size)

  Define a Sinc Kernel

  __init__(size)

    Constructor of a Sinc Kernel

    The kernel function is :

    > \[f(x) = S \cdot \sin \left( \frac{x + \epsilon}{s} \right) \cdot \frac{1}{x + \epsilon} \cdot \frac{1}{\pi \cdot S}\]

    With \(S\) the scale (\(S = s / 10\)) and \(\epsilon\) a minimal non nul value

    Parameters

      s – The size parameter (\(s\)) for the kernel

  __str__()

    Print the kernel type

    Return type

      `str`

class tracklib.core.Kernel.ExperimentalKernel(dmax, method='DTW', r=None)

  Non-parametric estimator of Kernel based on GPS tracks.

  The experimental covariogram kernel is initialized with a maximal scope dmax and an optional resolution, both given in ground units as a distance along curvilinear abscissa or traks. The comparison between pairs of tracks is performed with either Nearest Neighbor (NN) or Dynamic Time Warping (DTM) method. Some tests are still to be conducted to determine which one is more suitable for a robust covariance estimation. If no resolution is input, the covariogram is estimated in 30 points as a default value. The covariogram is incrementally estimated with each data input with addSamples (track_collection) or addTrackPair(track1, track2). Note that track collection input into addSamples must contain at least two tracks.

  Once an experimental covariogram has been estimated, it is possible to fit a parametric estimation on one of the kernel models provided above (except UniformKernel which is not a positive-definite function). The estimation is performed with fit(kernel) function.

  The fitted kernel is returned as standard output.

  __init__(dmax, method='DTW', r=None)

    Constructor of Experimental kernel

    Parameters

      - dmax (`float`) – TODO

      - method (`str`) – TODO

      - r (`Optional`[`float`]) – TODO

  addTrackPair(track1, track2)

    TODO

  addTrackCollection(trackCollection, verbose=False)

    TODO

  addDifferenceProfile(profile)

    add a Difference Profile

    Parameters

      profile (`Any`) – TODO

  __getGamma(scale=1)

    Return gamma value

    Parameters

      scale (`int`) – Scale value

    Return type

      `float`

    Returns

      Gamma value

  plot(sym='k+')

    Plot the kernel