示例#1
0
def Ipc(mol, avg=0, dMat=None, forceDMat=0):
    """This returns the information content of the coefficients of the characteristic
    polynomial of the adjacency matrix of a hydrogen-suppressed graph of a molecule.

    'avg = 1' returns the information content divided by the total population.

    From D. Bonchev & N. Trinajstic, J. Chem. Phys. vol 67, 4517-4533 (1977)

  """
    if forceDMat or dMat is None:
        if forceDMat:
            dMat = Chem.GetDistanceMatrix(mol, 0)
            mol._adjMat = dMat
        else:
            try:
                dMat = mol._adjMat
            except AttributeError:
                dMat = Chem.GetDistanceMatrix(mol, 0)
                mol._adjMat = dMat

    adjMat = numpy.equal(dMat, 1)
    cPoly = abs(Graphs.CharacteristicPolynomial(mol, adjMat))
    if avg:
        return entropy.InfoEntropy(cPoly)
    else:
        return sum(cPoly) * entropy.InfoEntropy(cPoly)
示例#2
0
def _CalculateEntropies(connectionDict, atomTypeDict, numAtoms):
    """
     Used by BertzCT
  """
    connectionList = list(connectionDict.values())
    totConnections = sum(connectionList)
    connectionIE = totConnections * (entropy.InfoEntropy(
        numpy.array(connectionList)) + math.log(totConnections) / _log2val)
    atomTypeList = list(atomTypeDict.values())
    atomTypeIE = numAtoms * entropy.InfoEntropy(numpy.array(atomTypeList))
    return atomTypeIE + connectionIE
示例#3
0
文件: ID3.py 项目: Kaziaa/rdkit-1
def CalcTotalEntropy(examples, nPossibleVals):
    """ Calculates the total entropy of the data set (w.r.t. the results)

   **Arguments**

    - examples: a list (nInstances long) of lists of variable values + instance
              values
    - nPossibleVals: a list (nVars long) of the number of possible values each variable
      can adopt.

   **Returns**

     a float containing the informational entropy of the data set.

  """
    nRes = nPossibleVals[-1]
    resList = numpy.zeros(nRes, 'i')
    for example in examples:
        res = int(example[-1])
        resList[res] += 1
    return entropy.InfoEntropy(resList)