Пример #1
0
def fastTanimotoSimilarity(A, nA, B):
    """Same as tanimotoSimilarity but expecting in A and B a long integer representing the binary fingetprint
       and nA the number of ONbits in A"""
    #Not validating input since this function has to called very often.
    AandB = A & B
    nAB = miscUtilities.countOnBits(AandB)  # Number of match ON Bits
    nAnB = 0.0 + nA + miscUtilities.countOnBits(B)  # nA+nB
    if not nAnB: return 0.0
    else: return nAB / (nAnB - nAB)
Пример #2
0
def fastTanimotoSimilarity(A,nA,B):
    """Same as tanimotoSimilarity but expecting in A and B a long integer representing the binary fingetprint
       and nA the number of ONbits in A"""
    #Not validating input since this function has to called very often.
    AandB = A & B
    nAB = miscUtilities.countOnBits(AandB)      # Number of match ON Bits
    nAnB = 0.0 + nA + miscUtilities.countOnBits(B)            # nA+nB
    if not nAnB: return 0.0
    else: return  nAB / (nAnB - nAB)
Пример #3
0
def tanimotoSimilarity(A, B):
    """Calculates the tanimnoto similarity defined by:
             ts = c/(a+b-c)
        where a is the number of bits in A
              b is the number of bits in B
              c is the number of bits in common
             
        A and B are the strings containing the bits
        This returns a value between 0 and 1:
                0 - Nothing in common
                1 - Identical
        len(A) and len(A) and len(B) are expected to be the same
    """
    #Not validating input since this function has to called very often.
    nAB = 0.0 + miscUtilities.countOnBits(int(A, 2) & int(B, 2))
    nAnB = A.count("1") + B.count("1")
    if not nAnB: return 0.0
    else: return nAB / (nAnB - nAB)
Пример #4
0
def tanimotoSimilarity(A, B):
    """Calculates the tanimnoto similarity defined by:
             ts = c/(a+b-c)
        where a is the number of bits in A
              b is the number of bits in B
              c is the number of bits in common
             
        A and B are the strings containing the bits
        This returns a value between 0 and 1:
                0 - Nothing in common
                1 - Identical
        len(A) and len(A) and len(B) are expected to be the same
    """
    #Not validating input since this function has to called very often.
    nAB = 0.0 + miscUtilities.countOnBits(int(A,2) & int(B,2))
    nAnB = A.count("1") + B.count("1")
    if not nAnB: return 0.0
    else: return  nAB / (nAnB - nAB)