TanimotoCoefficientSimilarity extends AbstractItemSimilarity implements UserSimilarity { @Override public double itemSimilarity(long itemID1, long itemID2) throws TasteException { int preferring1 = getDataModel().getNumUsersWithPreferenceFor(itemID1); return doItemSimilarity(itemID1, itemID2, preferring1); } TanimotoCoefficientSimilarity(DataModel dataModel); @Override void setPreferenceInferrer(PreferenceInferrer inferrer); @Override double userSimilarity(long userID1, long userID2); @Override double itemSimilarity(long itemID1, long itemID2); @Override double[] itemSimilarities(long itemID1, long[] itemID2s); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString();  }
@Test public void testReturnNaNDoubleWhenNoSimilaritiesForTwoItems() throws Exception { DataModel dataModel = getDataModel( new long[] {1, 2}, new Double[][] { {null, null, 3.0}, {1.0, 1.0, null}, }); Double similarity = new TanimotoCoefficientSimilarity(dataModel).itemSimilarity(1, 2); assertEquals(Double.NaN, similarity, EPSILON); }