/** * Convert a mapping of features and their counts to a binary fingerprint. Each feature * can set 1-n hashes, the amount is modified by the {@code bits} operand. * * @param features features to include * @param len fingerprint length * @param bits number of bits to set for each pattern * @return the continuous fingerprint */ public static IBitFingerprint makeBitFingerprint(final Map<String,Integer> features, int len, int bits) { final BitSetFingerprint fingerprint = new BitSetFingerprint(len); final Random rand = new Random(); for (String feature : features.keySet()) { int hash = feature.hashCode(); fingerprint.set(Math.abs(hash % len)); for (int i = 1; i < bits; i++) { rand.setSeed(hash); fingerprint.set(hash = rand.nextInt(len)); } } return fingerprint; }
@Override public IBitFingerprint getBitFingerprint(IAtomContainer container) throws CDKException { final BitSetFingerprint bitset = new BitSetFingerprint(getSize()); for (int r : radius) { final List<Sphere> spheres = generateAllSpheresFrom(container, r); final HashSet<Sphere> sphereHashSet = new HashSet<>(spheres); for (int k=0; k < this.spheres.length; ++k) { if (this.spheres[k].radius == r && sphereHashSet.contains(this.spheres[k])) bitset.set(k); } } return bitset; }
@Override public IBitFingerprint getBitFingerprint(IAtomContainer atomContainer) throws CDKException { BitSetFingerprint bitSetFingerprint = new BitSetFingerprint(getSize()); ShortestPathWalker walker = new ShortestPathWalker(atomContainer); for (String path : walker.paths) { final Integer i = bits.get(path); if (i != null) bitSetFingerprint.set(i); } return bitSetFingerprint; }
@Override public IBitFingerprint getBitFingerprint(IAtomContainer container) throws CDKException { final BitSetFingerprint bf = new BitSetFingerprint(getSize()); final ICountFingerprint icfp = circularFingerprinter.getCountFingerprint(container); for (int k=0, n = icfp.numOfPopulatedbins(); k < n; ++k) { final int index = HASH_SET.get(icfp.getHash(k)); if (index >= 0) { if (icfp.getCount(k)>0) bf.set(index, true); } } return bf; }