Package smile.math.distance
Class MinkowskiDistance
java.lang.Object
smile.math.distance.MinkowskiDistance
- All Implemented Interfaces:
Serializable
,ToDoubleBiFunction<double[],
,double[]> Distance<double[]>
,Metric<double[]>
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.
- See Also:
-
Constructor Summary
ConstructorDescriptionMinkowskiDistance
(int p) Constructor.MinkowskiDistance
(int p, double[] weight) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondouble
d
(double[] x, double[] y) Minkowski distance between the two arrays of type double.double
d
(float[] x, float[] y) Minkowski distance between the two arrays of type float.double
d
(int[] x, int[] y) Minkowski 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, wait
Methods inherited from interface smile.math.distance.Distance
apply, applyAsDouble, D, D
-
Constructor Details
-
MinkowskiDistance
public MinkowskiDistance(int p) Constructor.- Parameters:
p
- the order of Minkowski distance.
-
MinkowskiDistance
public MinkowskiDistance(int p, double[] weight) Constructor.- Parameters:
p
- the order of Minkowski distance.weight
- the weight vector.
-
-
Method Details
-
toString
-
d
public double d(int[] x, int[] y) Minkowski distance between the two arrays of type integer.- Parameters:
x
- a vector.y
- a vector.- Returns:
- the distance.
-
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.- Parameters:
x
- a vector.y
- a vector.- Returns:
- the distance.
-
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.
-