angular_distance#

skfda.misc.metrics.angular_distance = AngularDistance()#

Calculate the angular distance between two objects.

For each pair of observations x and y the angular distance between them is defined as the normalized “angle” between them:

\[d(x, y) = \frac{\arccos \left(\frac{\langle x, y \rangle}{ \sqrt{\langle x, x \rangle \langle y, y \rangle}} \right)}{\pi}\]

where \(\langle {}\cdot{}, {}\cdot{} \rangle\) is the inner product. This distance is defined in the interval [0, 1].

Parameters:
  • e1 (T) – First object.

  • e2 (T) – Second object.

Returns:

Numpy vector where the i-th coordinate has the angular distance between the i-th element of the first object and the i-th element of the second one.

Return type:

NDArrayFloat

Examples

Computes the angular 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 of size 2 with the computed l2 distance between the functions in the same position in both.

>>> import skfda
>>> import numpy as np
>>>
>>> x = np.linspace(0, 1, 1001)
>>> fd = skfda.FDataGrid([np.ones(len(x)), x], x)
>>> fd2 =  skfda.FDataGrid([2*np.ones(len(x)), np.cos(x)], x)
>>>
>>> skfda.misc.metrics.angular_distance(fd, fd2).round(2)
array([ 0.  ,  0.22])