Selected Reading

SciPy - maxinconsts() Method



The SciPy maxinconsts() method is used to calculate the distances between two datasets. Mostly, we use this function while calculating the matrix problem.

The usage this method will get to know Hausdorff distance[directed_hausdorff()] and see how to solve it from programming approach. The common use of Hausdorff distance is to find the distance calculation between two point sets.

Syntax

Following is the syntax of the SciPy maxinconsts() method −

maxinconsts(Z, R)
or,
directed_hausdorff(x, y)

Parameters

This method accepts the two parameter −

  • Z: This parameter is used to store the median data of given matrix.
  • R: This parameter store the built-in function named inconsistent() which convert the given matrix into an inconsistency matrix.
  • x, y: Both of these parameters work based on the same or different matrix.

Return value

This method return the result type as float value.

Example 1

Following is basic example which shows the usage of SciPy maxinconsts() method.

from scipy.cluster.hierarchy import median, inconsistent, maxinconsts
from scipy.spatial.distance import pdist
X = [[0, 0], [0, 1], [1, 0],
     [0, 4], [0, 3], [1, 4],
     [4, 0], [3, 0], [4, 1],
     [4, 4], [3, 4], [4, 3]]
Z = median(pdist(X))
R = inconsistent(Z)
res = maxinconsts(Z, R)
print(res)

Output

The above code produces the following output −

[0.         0.         0.         0.         0.70710678 0.70710678
 0.70710678 0.70710678 1.15470054 1.15470054 1.15470054]

Example 2

Below the program demonstrate the usage of Hausdorff ditances from two different array.

import numpy as np
from scipy.spatial.distance import directed_hausdorff
x = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
y = np.array([[0, 1], [1, 2]])

dist, index_x, index_y = directed_hausdorff(x, y)
print("Directed Hausdorff Distance:", dist)
print("Index in x:", index_x)
print("Index in y:", index_y)

Output

The above code produces the following output −

Directed Hausdorff Distance: 2.23606797749979
Index in x: 3
Index in y: 1
scipy_reference.htm
Advertisements