Package smile.math.distance
Class EuclideanDistance
java.lang.Object
smile.math.distance.EuclideanDistance
- All Implemented Interfaces:
Serializable,ToDoubleBiFunction<double[],,double[]> Distance<double[]>,Metric<double[]>
Euclidean distance. For float or double arrays, missing values (i.e. NaN)
are also handled.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.EuclideanDistance(double[] weight) Constructor with a given weight vector. -
Method Summary
Modifier and TypeMethodDescriptiondoubled(double[] x, double[] y) Euclidean distance between the two arrays of type double.doubled(float[] x, float[] y) Euclidean distance between the two arrays of type float.doubled(int[] x, int[] y) Euclidean distance between the two arrays of type integer.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface smile.math.distance.Distance
apply, applyAsDouble, D, D
-
Constructor Details
-
EuclideanDistance
public EuclideanDistance()Constructor. Standard (unweighted) Euclidean distance. -
EuclideanDistance
public EuclideanDistance(double[] weight) Constructor with a given weight vector.- Parameters:
weight- the weight vector.
-
-
Method Details
-
toString
-
d
public double d(int[] x, int[] y) Euclidean distance between the two arrays of type integer. No missing value handling in this method.- Parameters:
x- a vector.y- a vector.- Returns:
- the distance.
-
d
public double d(float[] x, float[] y) Euclidean distance between the two arrays of type float. NaN will be treated as missing values and will be excluded from the calculation. Let m be the number nonmissing values, and n be the number of all values. The returned distance is sqrt(n * d / m), where d is the square of distance between nonmissing values.- Parameters:
x- a vector.y- a vector.- Returns:
- the distance.
-
d
public double d(double[] x, double[] y) Euclidean distance between the two arrays of type double. NaN will be treated as missing values and will be excluded from the calculation. Let m be the number nonmissing values, and n be the number of all values. The returned distance is sqrt(n * d / m), where d is the square of distance between nonmissing values.
-