Class ManhattanDistance
java.lang.Object
smile.math.distance.ManhattanDistance
- All Implemented Interfaces:
Serializable, ToDoubleBiFunction<double[],double[]>, Distance<double[]>, Metric<double[]>
Manhattan distance, also known as L1 distance or L1
norm, is the sum of the (absolute) differences of their coordinates. Use
getInstance() to get the standard unweighted Manhattan distance. Or create
an instance with a specified weight vector. For float or double arrays,
missing values (i.e. NaN) are also handled.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubled(double[] x, double[] y) Manhattan distance between two arrays of type double.doubled(float[] x, float[] y) Manhattan distance between two arrays of type float.doubled(int[] x, int[] y) Manhattan distance between two arrays of type integer.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Distance
apply, applyAsDouble, pdist, pdist
-
Constructor Details
-
ManhattanDistance
public ManhattanDistance()Constructor. -
ManhattanDistance
public ManhattanDistance(double[] weight) Constructor.- Parameters:
weight- the weight vector.
-
-
Method Details
-
toString
-
d
public double d(int[] x, int[] y) Manhattan distance between two arrays of type integer.- Parameters:
x- a vector.y- a vector.- Returns:
- the distance.
-
d
public double d(float[] x, float[] y) Manhattan distance between two arrays of type float. NaN will be treated as missing values and will be excluded from the calculation. Let m be the number non-missing values, and n be the number of all values. The returned distance is n * d / m, where d is the distance between non-missing values.- Parameters:
x- a vector.y- a vector.- Returns:
- the distance.
-
d
public double d(double[] x, double[] y) Manhattan distance between two arrays of type double. NaN will be treated as missing values and will be excluded from the calculation. Let m be the number non-missing values, and n be the number of all values. The returned distance is n * d / m, where d is the distance between non-missing values.
-