Euclidean Distance#

ahrs.utils.metrics.euclidean(x: ndarray, y: ndarray) float#

Euclidean distance between Euler angles as described in [Huy09].

Given two sets of Euler angles \(\mathbf{x}\) and \(\mathbf{y}\), the Euclidean distance between them is computed as:

\[\Phi(\mathbf{x}, \mathbf{y}) = \sqrt{d(x_0, y_0)^2 + d(x_2, y_1)^2 + d(x_2, y_2)^2}\]

where the function \(d(\mathbf{x}, \mathbf{y})\) is the normalized difference between the two angles so that \(0 \leq d(\cdot, \cdot) \leq \pi\).

\[d(\mathbf{x}, \mathbf{y}) = \min \{ |\mathbf{x}-\mathbf{y}|, 2\pi - |\mathbf{x}-\mathbf{y}| \}\]

Warning

This metric is only valid for Euler angles in the range \([0, 2\pi]\) and is not in SO(3), since it depends on a representation that is not unique.

This metric gives values in the range [0, \(\pi\sqrt{3}\)]

Parameters:
  • x (numpy.ndarray) – M-by-N array to compare. Usually a reference array.

  • y (numpy.array) – M-by-N array to compare.

  • mode (str) – Mode of distance computation.

Returns:

d – Distance or difference between arrays.

Return type:

float

Examples

>>> import numpy as np
>>> from ahrs.utils.metrics import euclidean
>>> num_samples = 5
>>> angles = np.random.uniform(low=-180.0, high=180.0, size=(num_samples, 3))
>>> noisy = angles + np.random.randn(num_samples, 3)
>>> euclidean(angles, noisy)
2.585672169476804
>>> euclidean(angles, noisy, axis=0)
array([1.36319772, 1.78554071, 1.28032688])
>>> euclidean(angles, noisy, axis=1)     # distance per sample
array([0.88956871, 1.19727356, 1.5243858 , 0.68765523, 1.29007067])