smile.math.distance
Class MinkowskiDistance
- java.lang.Object
-
- smile.math.distance.MinkowskiDistance
-
public class MinkowskiDistance extends java.lang.Object implements Metric<double[]>, java.io.Serializable
Minkowski distance of order p or Lp-norm, is a generalization of Euclidean distance that is actually L2-norm. You may also provide 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 MinkowskiDistance(int p)Constructor.MinkowskiDistance(int p, double[] weight)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doubled(double[] x, double[] y)Minkowski distance between the two arrays of type double.doubled(float[] x, float[] y)Minkowski distance between the two arrays of type float.doubled(int[] x, int[] y)Minkowski distance between the two arrays of type integer.java.lang.StringtoString()
-
-
-
Constructor Detail
-
MinkowskiDistance
public MinkowskiDistance(int p)
Constructor.
-
MinkowskiDistance
public MinkowskiDistance(int p, double[] weight)Constructor.- 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)Minkowski distance between the two arrays of type integer.
-
d
public double d(float[] x, float[] y)Minkowski 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 non-missing values, and n be the number of all values. The returned distance is pow(n * d / m, 1/p), where d is the p-pow of distance between non-missing values.
-
d
public double d(double[] x, double[] y)Minkowski 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 non-missing values, and n be the number of all values. The returned distance is pow(n * d / m, 1/p), where d is the p-pow of distance between non-missing values.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG