LpDistance#
- class skfda.misc.metrics.LpDistance(p, vector_norm=None)[source]#
Lp distance for functional data objects.
Calculates the distance between two functional objects.
For each pair of observations f and g the distance between them is defined as:
\[d(x, y) = \| x - y \|_p\]where \(\| {}\cdot{} \|_p\) denotes the
Lp norm
.The objects
l1_distance
,l2_distance
andlinf_distance
are instances of this class with commonly used values ofp
, namely 1, 2 and infinity.- Parameters:
Examples
Computes the distances between an object containing functional data corresponding to the functions y = 1 and y = x defined over the interval [0, 1] and another ones containing data of the functions y = 0 and y = x/2. The result then is an array 2x2 with the computed l2 distance between every pair of functions.
>>> import skfda >>> import numpy as np >>> >>> x = np.linspace(0, 1, 1001) >>> fd = skfda.FDataGrid([np.ones(len(x))], x) >>> fd2 = skfda.FDataGrid([np.zeros(len(x))], x) >>> >>> distance = skfda.misc.metrics.LpDistance(p=2) >>> distance(fd, fd2).round(2) array([ 1.])
If the functional data are defined over a different set of points of discretisation the functions returns an exception.
>>> x = np.linspace(0, 2, 1001) >>> fd2 = skfda.FDataGrid([np.zeros(len(x)), x/2 + 0.5], x) >>> distance = skfda.misc.metrics.LpDistance(p=2) >>> distance(fd, fd2) Traceback (most recent call last): ... ValueError: ...
Methods
Examples using skfda.misc.metrics.LpDistance
#
Meteorological data: data visualization, clustering, and functional PCA
Radius neighbors classification