curvesimilarities.frechet.fd(P, Q, *, rel_tol=0.0, abs_tol=2.220446049250313e-16)[source]#
(Continuous) Fréchet distance between two open polygonal curves.
Let \(f: [0, 1] \to \Omega\) and \(g: [0, 1] \to \Omega\) be curves
where \(\Omega\) is a metric space. The Fréchet distance between
\(f\) and \(g\) is defined as
where \(\alpha, \beta: [0, 1] \to [0, 1]\) are continuous non-decreasing
surjections and \(\lVert \cdot \rVert\) is the underlying metric, which
is the Euclidean metric in this implementation.
Parameters:
Parray_like
A \(p\) by \(n\) array of \(p\) vertices in an
\(n\)-dimensional space.
Qarray_like
A \(q\) by \(n\) array of \(q\) vertices in an
\(n\)-dimensional space.
rel_tol, abs_toldouble
Relative and absolute tolerances for parametric search of the Fréchet distance.
The search is terminated if the upper boundary a and the lower boundary
b satisfy: a-b<=max(rel_tol*a,abs_tol).
Returns:
distdouble
The (continuous) Fréchet distance between P and Q, NaN if any vertice
is empty.
Raises:
ValueError
If P and Q are not 2-dimensional arrays with same number of columns.
Notes
This function implements Alt and Godau’s algorithm [1].
Discrete Fréchet distance between two two ordered sets of points.
Let \(\{P_0, P_1, ..., P_n\}\) and \(\{Q_0, Q_1, ..., Q_m\}\) be ordered
sets of points in metric space. The discrete Fréchet distance between two sets is
defined as
where \(C\) is a nondecreasing coupling over
\(\{0, ..., n\} \times \{0, ..., m\}\), starting from \((0, 0)\) and
ending with \((n, m)\). \(\lVert \cdot \rVert\) is the underlying
metric, which is the Euclidean metric in this implementation.
Parameters:
Parray_like
An \(p\) by \(n\) array of \(p\) vertices in an
\(n\)-dimensional space.
Qarray_like
An \(q\) by \(n\) array of \(q\) vertices in an
\(n\)-dimensional space.
Returns:
distdouble
The discrete Fréchet distance between P and Q, NaN if any vertice
is empty.
Raises:
ValueError
If P and Q are not 2-dimensional arrays with same number of columns.
Notes
This function implements Eiter and Mannila’s algorithm [2].
This module implements only the basic algorithm. If you need advanced features, use
dedicated packages such as dtw-python.
curvesimilarities.dtw.dtw(P, Q, dist='euclidean')[source]#
Dynamic time warping distance between two ordered sets of points.
Let \(\{P_0, P_1, ..., P_n\}\) and \(\{Q_0, Q_1, ..., Q_m\}\) be ordered
sets of points in metric space. The dynamic time warping distance between
two sets is defined as
curvesimilarities.integfrechet.ifd(P, Q, delta, dist='euclidean')[source]#
Integral Fréchet distance between two open polygonal curves.
Let \(f, g: [0, 1] \to \Omega\) be curves defined in a metric space
\(\Omega\). Let \(\alpha, \beta: [0, 1] \to [0, 1]\) be continuous
non-decreasing surjections, and define \(\pi: [0, 1] \to [0, 1] \times
[0, 1]\) such that \(\pi(t) = \left(\alpha(t), \beta(t)\right)\).
The integral Fréchet distance between \(f\) and \(g\) is defined as
where \(dist\left(\pi(t)\right)\) is a distance between
\(f\left(\alpha(t)\right)\) and \(g\left(\beta(t)\right)\) and
\(\lVert \cdot \rVert_1\) is the Manhattan norm.
Parameters:
Parray_like
A \(p\) by \(n\) array of \(p\) vertices in an
\(n\)-dimensional space.
Qarray_like
A \(q\) by \(n\) array of \(q\) vertices in an
\(n\)-dimensional space.
deltadouble
Maximum length of edges between Steiner points.
Refer to the Reference section for more information.
dist{‘euclidean’, ‘squared_euclidean’}
Type of \(dist\). Refer to the Notes section for more information.
Returns:
double
The integral Fréchet distance between P and Q, NaN if any vertice
is empty or both vertices consist of a single point.
Raises:
ValueError
If P and Q are not 2-dimensional arrays with same number of columns.
A \(p\) by \(n\) array of \(p\) vertices in an
\(n\)-dimensional space.
paramarray_like
An 1-D array of \(q\) parameters for sampled points.
Natural parametrization is used, i.e., the polygonal curve
is parametrized by its arc length.
Parameters smaller than \(0\) or larger than the total
arc length are clipped to the nearest valid value.