smile.math.distance
Class EuclideanDistance
- java.lang.Object
-
- smile.math.distance.EuclideanDistance
-
public class EuclideanDistance extends java.lang.Object implements Metric<double[]>, java.io.Serializable
Euclidean distance. Use getInstance() to get the standard unweighted Euclidean distance. Or create an instance with a specified weight vector. For float or double arrays, missing values (i.e. NaN) are also handled. Also support sparse arrays of which zeros are excluded to save space.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description EuclideanDistance()Constructor.EuclideanDistance(double[] weight)Constructor with a given weight vector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doubled(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.java.lang.StringtoString()
-
-
-
Constructor Detail
-
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 Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
d
public double d(int[] x, int[] y)Euclidean distance between the two arrays of type integer. No missing value handling in this method.
-
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.
-
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.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG