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 and linf_distance are instances of this class with commonly used values of p, namely 1, 2 and infinity.

Parameters:
  • p (float) – p of the lp norm. Must be greater or equal than 1. If p=math.inf it is used the L infinity metric. Defaults to 2.

  • vector_norm (Union[Norm[NDArrayFloat], float, None]) – vector norm to apply. If it is a float, is the index of the multivariate lp norm. Defaults to the same as p.

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

Meteorological data: data visualization, clustering, and functional PCA

Outlier detection with FPCA

Outlier detection with FPCA

Radius neighbors classification

Radius neighbors classification