bundles / scipy latest / scipy / spatial / distance / directed_hausdorff
function
scipy.spatial.distance:directed_hausdorff
source: /scipy/spatial/distance.py :304
Signature
def directed_hausdorff ( u , v , rng = 0 , * , seed = None ) Summary
Compute the directed Hausdorff distance between two 2-D arrays.
Extended Summary
Distances between pairs are calculated using a Euclidean metric.
Parameters
u: (M,N) array_likeInput array with M points in N dimensions.
v: (O,N) array_likeInput array with O points in N dimensions.
rng: int or `numpy.random.Generator` or None, optionalPseudorandom number generator state. Default is 0 so the shuffling of
uandvis reproducible.If
rngis passed by keyword, types other than numpy.random.Generator are passed to numpy.random.default_rng to instantiate aGenerator. Ifrngis already aGeneratorinstance, then the provided instance is used.If this argument is passed by position or
seedis passed by keyword, legacy behavior for the argumentseedapplies:If
seedis None, a newRandomStateinstance is used. The state is initialized using data from/dev/urandom(or the Windows analogue) if available or from the system clock otherwise.If
seedis an int, a newRandomStateinstance is used, seeded withseed.If
seedis already aGeneratororRandomStateinstance, then that instance is used.
Returns
d: doubleThe directed Hausdorff distance between arrays
uandv,index_1: intindex of point contributing to Hausdorff pair in
uindex_2: intindex of point contributing to Hausdorff pair in
v
Raises
: ValueErrorAn exception is thrown if
uandvdo not have the same number of columns.
Notes
Uses the early break technique and the random sampling approach described by [1]. Although worst-case performance is O(m * o) (as with the brute force algorithm), this is unlikely in practice as the input data would have to require the algorithm to explore every single point interaction, and after the algorithm shuffles the input points at that. The best case performance is O(m), which is satisfied by selecting an inner loop distance that is less than cmax and leads to an early break as often as possible. The authors have formally shown that the average runtime is closer to O(m).
Examples
Find the directed Hausdorff distance between two 2-D arrays of coordinates:from scipy.spatial.distance import directed_hausdorff import numpy as np u = np.array([(1.0, 0.0), (0.0, 1.0), (-1.0, 0.0), (0.0, -1.0)]) v = np.array([(2.0, 0.0), (0.0, 2.0), (-2.0, 0.0), (0.0, -4.0)])✓
directed_hausdorff(u, v)[0] directed_hausdorff(v, u)[0]✓
max(directed_hausdorff(u, v)[0], directed_hausdorff(v, u)[0])
✓directed_hausdorff(v, u)[1:]
✓See also
- scipy.spatial.procrustes
Another similarity test for two data sets
Aliases
-
scipy.spatial.distance.directed_hausdorff