@Test public void testDistanceInt() { System.out.println("distance"); int[] x = {1, 2, 3, 4}; int[] y = {4, 3, 2, 1}; assertEquals(8, new ManhattanDistance().d(x, y), 1E-6); }
public double d(int[] x, int[] y) { if (x.length != y.length) throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length)); double dist = 0.0; if (weight == null) { for (int i = 0; i < x.length; i++) { dist += Math.abs(x[i] - y[i]); } } else { if (x.length != weight.length) throw new IllegalArgumentException(String.format("Input vectors and weight vector have different length: %d, %d", x.length, weight.length)); for (int i = 0; i < x.length; i++) { dist += weight[i] * Math.abs(x[i] - y[i]); } } return dist; }
ManhattanDistance implements Metric<double[]> { public double d(int[] x, int[] y) { if (x.length != y.length) throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length)); double dist = 0.0; if (weight == null) { for (int i = 0; i < x.length; i++) { dist += Math.abs(x[i] - y[i]); } } else { if (x.length != weight.length) throw new IllegalArgumentException(String.format("Input vectors and weight vector have different length: %d, %d", x.length, weight.length)); for (int i = 0; i < x.length; i++) { dist += weight[i] * Math.abs(x[i] - y[i]); } } return dist; } }
ManhattanDistance implements Metric<double[]> { public double d(int[] x, int[] y) { if (x.length != y.length) throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length)); double dist = 0.0; if (weight == null) { for (int i = 0; i < x.length; i++) { dist += Math.abs(x[i] - y[i]); } } else { if (x.length != weight.length) throw new IllegalArgumentException(String.format("Input vectors and weight vector have different length: %d, %d", x.length, weight.length)); for (int i = 0; i < x.length; i++) { dist += weight[i] * Math.abs(x[i] - y[i]); } } return dist; } ManhattanDistance();  ManhattanDistance(double[] weight); }
ManhattanDistance implements Metric<double[]> { public double d(int[] x, int[] y) { if (x.length != y.length) throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length)); double dist = 0.0; if (weight == null) { for (int i = 0; i < x.length; i++) { dist += Math.abs(x[i] - y[i]); } } else { if (x.length != weight.length) throw new IllegalArgumentException(String.format("Input vectors and weight vector have different length: %d, %d", x.length, weight.length)); for (int i = 0; i < x.length; i++) { dist += weight[i] * Math.abs(x[i] - y[i]); } } return dist; } ManhattanDistance();  ManhattanDistance(double[] weight); @Override String toString(); double d(int[] x, int[] y); double d(float[] x, float[] y); @Override double d(double[] x, double[] y); }
ManhattanDistance implements Metric<double[]> { public double d(int[] x, int[] y) { if (x.length != y.length) throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length)); double dist = 0.0; if (weight == null) { for (int i = 0; i < x.length; i++) { dist += Math.abs(x[i] - y[i]); } } else { if (x.length != weight.length) throw new IllegalArgumentException(String.format("Input vectors and weight vector have different length: %d, %d", x.length, weight.length)); for (int i = 0; i < x.length; i++) { dist += weight[i] * Math.abs(x[i] - y[i]); } } return dist; } ManhattanDistance();  ManhattanDistance(double[] weight); @Override String toString(); double d(int[] x, int[] y); double d(float[] x, float[] y); @Override double d(double[] x, double[] y);  }