/** * Wrap a mapping of features and their counts to a continuous (count based) fingerprint. * * @param features features to include * @return the continuous fingerprint */ public static ICountFingerprint makeCountFingerprint(final Map<String,Integer> features) { return new IntArrayCountFingerprint(features); }
@Test public void testMerge() { IntArrayCountFingerprint fp1 = new IntArrayCountFingerprint(new HashMap<String, Integer>() { IntArrayCountFingerprint fp2 = new IntArrayCountFingerprint(new HashMap<String, Integer>() { for (int i = 0; i < fp1.numOfPopulatedbins(); i++) { hashCounts.put(fp1.getHash(i), fp1.getCount(i)); for (int i = 0; i < fp2.numOfPopulatedbins(); i++) { int hash = fp2.getHash(i); Integer count = hashCounts.get(hash); if (count == null) { count = 0; hashCounts.put(hash, count + fp2.getCount(i)); fp1.merge(fp2); assertEquals(fp1.numOfPopulatedbins(), hashCounts.size()); for (int i = 0; i < fp1.numOfPopulatedbins(); i++) { Integer hash = fp1.getHash(i); Integer count = fp1.getCount(i); assertTrue(hashCounts.containsKey(hash)); assertEquals(count, hashCounts.get(hash));
@Override public ICountFingerprint getCountFingerprint(IAtomContainer container) throws CDKException { return new IntArrayCountFingerprint(getRawFingerprint(container)); }
@Test public void method2() 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.75, Tanimoto.method2(fp1, fp2), 0.001); }
@Test public void method1() 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); }
@Test 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); IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.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); }