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()
../../_images/simplify_gaussian_filter.png

Figure 1: Simplification with a gaussian kernel filter#

class tracklib.core.Kernel.Kernel(function, support)[source]#

Generic kernel class

__filter_boundary = False#

TODO

__kernel_function = None#

TODO

__support = None#

TODO

__init__(function, support)[source]#

Kernel constructor

Parameters
  • function (Callable[[float], float]) – Kernel function

  • support (float) – Kernel support

setFilterBoundary(bool)[source]#

Set filter boundary

Parameters

bool (bool) – TODO

filterBoundary()[source]#

Return the filterBoundary parameter value

Return type

bool

Returns

filterBoundary value

setFunction(function)[source]#

Set the function used by Kernel

Parameters

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

getFunction()[source]#

Return the function used by the kernel

Return type

Callable[[float], float]

Returns

A kernel function

plot(append=False)[source]#

Plot the kernel

Parameters

append (bool) – TODO

evaluate(x)[source]#

Evaluate the kernel for a given value

Parameters

x (float) – Value to evaluate

Retun

Kernel value

Return type

float

toSlidingWindow()[source]#

Transform the kernel in a sliding windows

Return type

list[int]

Returns

A sliding windows

class tracklib.core.Kernel.DiracKernel[source]#

Define a DiracKernel

__init__()[source]#

Constructor of a dirac kernel

__str__()[source]#

Print the kernel type

Return type

str

class tracklib.core.Kernel.UniformKernel(size)[source]#

Define a unifomr kernel

__init__(size)[source]#

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__()[source]#

Print the kernel type

Return type

str

class tracklib.core.Kernel.TriangularKernel(size)[source]#

Define a triangular kernel

__init__(size)[source]#

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__()[source]#

Print the kernel type

Return type

str

class tracklib.core.Kernel.GaussianKernel(sigma)[source]#

Define a Gaussian Kernel

__init__(sigma)[source]#

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__()[source]#

Print the kernel type

Return type

str

class tracklib.core.Kernel.ExponentialKernel(sigma)[source]#

Define an Exponential Kernel

__init__(sigma)[source]#

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__()[source]#

Print the kernel type

Return type

str

class tracklib.core.Kernel.EpanechnikovKernel(size)[source]#

Define a Epanechnikov Kernel

__init__(size)[source]#

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__()[source]#

Print the kernel type

Return type

str

class tracklib.core.Kernel.SincKernel(size)[source]#

Define a Sinc Kernel

__init__(size)[source]#

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__()[source]#

Print the kernel type

Return type

str

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

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)[source]#

Constructor of Experimental kernel

Parameters
  • dmax (float) – TODO

  • method (str) – TODO

  • r (Optional[float]) – TODO

addTrackPair(track1, track2)[source]#

TODO

addTrackCollection(trackCollection, verbose=False)[source]#

TODO

addDifferenceProfile(profile)[source]#

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+')[source]#

Plot the kernel