Example #1
0
 public void TestAnd()
 {
     TestGetAndSet();
     bitsetFP.And(CreateFP2());
     Assert.IsFalse(bitsetFP[0]);
     Assert.IsFalse(bitsetFP[1]);
     Assert.IsFalse(bitsetFP[2]);
     Assert.IsTrue(bitsetFP[3]);
 }
Example #2
0
        /// <summary>
        /// Evaluates Tanimoto coefficient for two <see cref="IBitFingerprint"/>.
        /// </summary>
        /// <param name="fingerprint1">fingerprint for the first molecule</param>
        /// <param name="fingerprint2">fingerprint for the second molecule</param>
        /// <returns>The Tanimoto coefficient</returns>
        /// <exception cref="ArgumentException">if bitsets are not of the same length</exception>
        public static double Calculate(IBitFingerprint fingerprint1, IBitFingerprint fingerprint2)
        {
            if (fingerprint1.Length != fingerprint2.Length)
            {
                throw new ArgumentException("Fingerprints must have the same size");
            }
            int cardinality1 = fingerprint1.Cardinality;
            int cardinality2 = fingerprint2.Cardinality;
            // If the fingerprint is an IntArrayFingeprint that could mean a big
            // fingerprint so let's take the safe way out and create a
            // new IntArrayfingerprint
            IBitFingerprint one_and_two = fingerprint1 is IntArrayFingerprint ? (IBitFingerprint) new IntArrayFingerprint(
                fingerprint1) : (IBitFingerprint) new BitSetFingerprint(fingerprint1);

            one_and_two.And(fingerprint2);
            double cardinalityCommon = one_and_two.Cardinality;

            return(cardinalityCommon / (cardinality1 + cardinality2 - cardinalityCommon));
        }