@Test public void testDistance() { System.out.println("distance"); Set<Integer> a = new HashSet<>(); a.add(1); a.add(2); a.add(3); a.add(4); Set<Integer> b = new HashSet<>(); b.add(3); b.add(4); b.add(5); b.add(6); assertEquals(0.6666667, JaccardDistance.d(a, b), 1E-7); }
@Override public double d(T[] a, T[] b) { Set<T> union = new HashSet<>(); Set<T> intersection = new HashSet<>(); for (int i = 0; i < b.length; i++) { union.add(b[i]); } for (int i = 0; i < a.length; i++) { intersection.add(a[i]); } intersection.retainAll(union); for (int i = 0; i < a.length; i++) { union.add(a[i]); } return 1.0 - (double) intersection.size() / union.size(); }
JaccardDistance implements Distance<T[]> { @Override public double d(T[] a, T[] b) { Set<T> union = new HashSet<>(); Set<T> intersection = new HashSet<>(); for (int i = 0; i < b.length; i++) { union.add(b[i]); } for (int i = 0; i < a.length; i++) { intersection.add(a[i]); } intersection.retainAll(union); for (int i = 0; i < a.length; i++) { union.add(a[i]); } return 1.0 - (double) intersection.size() / union.size(); } }
JaccardDistance implements Distance<T[]> { @Override public double d(T[] a, T[] b) { Set<T> union = new HashSet<>(); Set<T> intersection = new HashSet<>(); for (int i = 0; i < b.length; i++) { union.add(b[i]); } for (int i = 0; i < a.length; i++) { intersection.add(a[i]); } intersection.retainAll(union); for (int i = 0; i < a.length; i++) { union.add(a[i]); } return 1.0 - (double) intersection.size() / union.size(); } JaccardDistance(); }
JaccardDistance implements Distance<T[]> { @Override public double d(T[] a, T[] b) { Set<T> union = new HashSet<>(); Set<T> intersection = new HashSet<>(); for (int i = 0; i < b.length; i++) { union.add(b[i]); } for (int i = 0; i < a.length; i++) { intersection.add(a[i]); } intersection.retainAll(union); for (int i = 0; i < a.length; i++) { union.add(a[i]); } return 1.0 - (double) intersection.size() / union.size(); } JaccardDistance(); @Override String toString(); @Override double d(T[] a, T[] b); static double d(Set<T> a, Set<T> b); }
JaccardDistance implements Distance<T[]> { @Override public double d(T[] a, T[] b) { Set<T> union = new HashSet<>(); Set<T> intersection = new HashSet<>(); for (int i = 0; i < b.length; i++) { union.add(b[i]); } for (int i = 0; i < a.length; i++) { intersection.add(a[i]); } intersection.retainAll(union); for (int i = 0; i < a.length; i++) { union.add(a[i]); } return 1.0 - (double) intersection.size() / union.size(); } JaccardDistance(); @Override String toString(); @Override double d(T[] a, T[] b); static double d(Set<T> a, Set<T> b);  }