Permalink
Browse files

fix for tanimoto method 2 + test

  • Loading branch information...
1 parent f2b2067 commit c6e85e028b595803b684e7555c5e4759eeacfdde @jonalv jonalv committed with egonw Jun 20, 2011
@@ -225,23 +225,27 @@ public static float method2( ICountFingerprint fp1,
j = 0;
while ( i < fp1.numOfPopulatedbins()
|| j < fp2.numOfPopulatedbins() ) {
- int hash1 = fp1.getHash(i);
- int hash2 = fp2.getHash(j);
- int count1 = fp1.getCount(i);
- int count2 = fp2.getCount(j);
+ Integer hash1 = i < fp1.numOfPopulatedbins() ? fp1.getHash(i)
+ : null;
+ Integer hash2 = j < fp2.numOfPopulatedbins() ? fp2.getHash(j)
+ : null;
+ Integer count1 = i < fp1.numOfPopulatedbins() ? fp1.getCount(i)
+ : null;
+ Integer count2 = j < fp2.numOfPopulatedbins() ? fp2.getCount(j)
+ : null;
- if ( hash1 < hash2) {
+ if ( count2 == null || (hash1 != null && hash1 < hash2) ) {
maxSum += count1;
i++;
continue;
}
- if ( hash1 > hash2 ) {
+ if ( count1 == null || (hash2 != null && hash1 > hash2 ) ) {
maxSum += count2;
j++;
continue;
}
- if ( hash1 == hash2 ) {
+ if ( hash1.equals(hash2) ) {
maxSum += Math.max(count1, count2);
minSum += Math.min(count1, count2);
i++;
@@ -188,18 +188,26 @@ public void testRawTanimotoBetween0and1() throws Exception {
}
@Test
- public void testCountMethod1and2() {
- IntArrayCountFingerprint fp1 = new IntArrayCountFingerprint(
- new HashMap<String, Integer>() {{
- put("A", 3);
- }}
- );
- IntArrayCountFingerprint fp2 = new IntArrayCountFingerprint(
- new HashMap<String, Integer>() {{
- put("A", 4);
- }}
- );
+ public void testCountMethod1and2() throws CDKException {
+ ICountFingerprint fp1 = new IntArrayCountFingerprint(
+ new HashMap<String, Integer>() {{
+ put("A", 3);
+ }}
+ );
+ ICountFingerprint fp2 = new IntArrayCountFingerprint(
+ new HashMap<String, Integer>() {{
+ put("A", 4);
+ }}
+ );
Assert.assertEquals(0.923, Tanimoto.method1(fp1, fp2), 0.001 );
Assert.assertEquals(0.75, Tanimoto.method2(fp1, fp2), 0.001 );
+
+ Molecule mol1 = MoleculeFactory.makeIndole();
+ Molecule mol2 = MoleculeFactory.makeIndole();
+ SignatureFingerprinter fingerprinter = new SignatureFingerprinter();
+ fp1 = fingerprinter.getCountFingerprint(mol1);
+ fp2 = fingerprinter.getCountFingerprint(mol2);
+ Assert.assertEquals(1.0, Tanimoto.method1(fp1, fp2), 0.001);
+ Assert.assertEquals(1.0, Tanimoto.method2(fp1, fp2), 0.001);
}
}

0 comments on commit c6e85e0

Please sign in to comment.