@Test public void testCalDistanceMatrixMatrix() { FastDistanceMatrixData matrixData = initMatrixData(); DenseMatrix res = distance.calc(matrixData, matrixData); double[] expect = new double[] {0.0, 0.2852, 0.2852, 0.0}; double[] predict = res.getData(); for (int i = 0; i < expect.length; i++) { Assert.assertEquals(expect[i], predict[i], 0.01); } }
@Override public double calc(double[] array1, double[] array2) { double dot = BLAS.dot(array1, array2); double cross = Math.sqrt(BLAS.dot(array1, array1) * BLAS.dot(array2, array2)); return 1.0 - (cross > 0.0 ? dot / cross : 0.0); }
CosineDistance extends FastDistance { @Override public double calc(double[] array1, double[] array2) { double dot = BLAS.dot(array1, array2); double cross = Math.sqrt(BLAS.dot(array1, array1) * BLAS.dot(array2, array2)); return 1.0 - (cross > 0.0 ? dot / cross : 0.0); } }
CosineDistance extends FastDistance { @Override public double calc(double[] array1, double[] array2) { double dot = BLAS.dot(array1, array2); double cross = Math.sqrt(BLAS.dot(array1, array1) * BLAS.dot(array2, array2)); return 1.0 - (cross > 0.0 ? dot / cross : 0.0); }  }
CosineDistance extends FastDistance { @Override public double calc(double[] array1, double[] array2) { double dot = BLAS.dot(array1, array2); double cross = Math.sqrt(BLAS.dot(array1, array1) * BLAS.dot(array2, array2)); return 1.0 - (cross > 0.0 ? dot / cross : 0.0); }  @Override double calc(double[] array1, double[] array2); @Override double calc(Vector vec1, Vector vec2); @Override void updateLabel(FastDistanceData data); }
CosineDistance extends FastDistance { @Override public double calc(double[] array1, double[] array2) { double dot = BLAS.dot(array1, array2); double cross = Math.sqrt(BLAS.dot(array1, array1) * BLAS.dot(array2, array2)); return 1.0 - (cross > 0.0 ? dot / cross : 0.0); }  @Override double calc(double[] array1, double[] array2); @Override double calc(Vector vec1, Vector vec2); @Override void updateLabel(FastDistanceData data);  }