@Test public void testContinuousDistance() { Assert.assertEquals(distance.calc(denseVector1, denseVector2), 0.2852, 0.01); Assert.assertEquals(distance.calc(denseVector1.getData(), denseVector2.getData()), 0.2852, 0.01); Assert.assertEquals(distance.calc(denseVector1, sparseVector1), 0.73, 0.01); Assert.assertEquals(distance.calc(sparseVector1, sparseVector2), 0.76, 0.01); Assert.assertEquals(distance.calc(sparseVector1, denseVector2), 0.60, 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);  }