LpNorm#

class skfda.misc.metrics.LpNorm(p, vector_norm=None)[source]#

Norm of all the observations in a FDataGrid object.

For each observation f the Lp norm is defined as:

\[\| f \| = \left( \int_D \| f \|^p dx \right)^{ \frac{1}{p}}\]

Where D is the domain over which the functions are defined.

The integral is approximated using Simpson’s rule.

In general, if f is a multivariate function \((f_1, ..., f_d)\), and \(D \subset \mathbb{R}^n\), it is applied the following generalization of the Lp norm.

\[\| f \| = \left( \int_D \| f \|_{*}^p dx \right)^{ \frac{1}{p}}\]

Where \(\| \cdot \|_*\) denotes a vectorial norm. See vectorial_norm() to more information.

For example, if \(f: \mathbb{R}^2 \rightarrow \mathbb{R}^2\), and \(\| \cdot \|_*\) is the euclidean norm \(\| (x,y) \|_* = \sqrt{x^2 + y^2}\), the lp norm applied is

\[\| f \| = \left( \int \int_D \left ( \sqrt{ \| f_1(x,y) \|^2 + \| f_2(x,y) \|^2 } \right )^p dxdy \right)^{ \frac{1}{p}}\]

The objects l1_norm, l2_norm and linf_norm 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 (Norm[ndarray[Any, dtype[float64]]] | 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

Calculates the norm of a FDataGrid containing the functions y = 1 and y = x defined in the interval [0,1].

>>> import skfda
>>> import numpy as np
>>>
>>> x = np.linspace(0, 1, 1001)
>>> fd = skfda.FDataGrid([np.ones(len(x)), x] ,x)
>>> norm = skfda.misc.metrics.LpNorm(2)
>>> norm(fd).round(2)
array([ 1.  ,  0.58])

As the norm with p=2 is a common choice, one can use l2_norm directly:

>>> skfda.misc.metrics.l2_norm(fd).round(2)
array([ 1.  ,  0.58])

The lp norm is only defined if p >= 1.

>>> norm = skfda.misc.metrics.LpNorm(0.5)
Traceback (most recent call last):
    ....
ValueError: p (=0.5) must be equal or greater than 1.

Methods

Examples using skfda.misc.metrics.LpNorm#

Outlier detection with FPCA

Outlier detection with FPCA