lp_norm#
- skfda.misc.metrics.lp_norm(vector, *, p, vector_norm=None)[source]#
Calculate the 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}}\]Note
This function is a wrapper of
LpNorm
, available only for convenience. As the parameterp
is mandatory, it cannot be used where a fully-defined norm is required: use an instance ofLpNorm
in those cases.- Parameters:
vector (ndarray[Any, dtype[float64]] | FData) – Vector object.
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
.
- Returns:
Matrix with as many rows as observations in the first object and as many columns as observations in the second one. Each element (i, j) of the matrix is the inner product of the ith observation of the first object and the jth observation of the second one.
- Return type:
numpy.darray
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) >>> skfda.misc.metrics.lp_norm(fd, p=2).round(2) array([ 1. , 0.58])
As the norm with
p=2
is a common choice, one can usel2_norm
directly:>>> skfda.misc.metrics.l2_norm(fd).round(2) array([ 1. , 0.58])
The lp norm is only defined if p >= 1.
>>> skfda.misc.metrics.lp_norm(fd, p=0.5) Traceback (most recent call last): .... ValueError: p (=0.5) must be equal or greater than 1.
See also