rdkit.ML.InfoTheory.rdInfoTheory module¶
Module containing bunch of functions for information metrics and a ranker to rank bits
- class rdkit.ML.InfoTheory.rdInfoTheory.BitCorrMatGenerator(self)¶
Bases:
objectA class to generate a pairwise correlation matrix between a list of bits The mode of operation for this class is something like this
>>> cmg = BitCorrMatGenerator() >>> cmg.SetBitList(blist) >>> for fp in fpList: >>> cmg.CollectVotes(fp) >>> corrMat = cmg.GetCorrMatrix()
The resulting correlation matrix is a one dimensional nummeric array containing the lower triangle elements
- CollectVotes(self, bitVect: object) None¶
For each pair of on bits (bi, bj) in fp increase the correlation count for the pair by 1
- Parameters:
fp (-) – a bit vector to collect the fingerprints from
- GetCorrMatrix(self) numpy.ndarray[dtype=float64, shape=(*)]¶
Get the correlation matrix following the collection of votes from a bunch of fingerprints
- class rdkit.ML.InfoTheory.rdInfoTheory.InfoBitRanker(self, nBits: int, nClasses: int)¶
- class rdkit.ML.InfoTheory.rdInfoTheory.InfoBitRanker(self, nBits: int, nClasses: int, infoType: rdkit.ML.InfoTheory.rdInfoTheory.InfoType)
Bases:
objectA class to rank the bits from a series of labelled fingerprints A simple demonstration may help clarify what this class does. Here’s a small set of vectors:
>>> for i,bv in enumerate(bvs): print(bv.ToBitString(),acts[i]) ... 0001 0 0101 0 0010 1 1110 1
Default ranker, using infogain:
>>> ranker = InfoBitRanker(4,2) >>> for i,bv in enumerate(bvs): ranker.AccumulateVotes(bv,acts[i]) ... >>> for bit,gain,n0,n1 in ranker.GetTopN(3): print(int(bit),'%.3f'%gain,int(n0),int(n1)) ... 3 1.000 2 0 2 1.000 0 2 0 0.311 0 1
Using the biased infogain:
>>> ranker = InfoBitRanker(4,2,InfoTheory.InfoType.BIASENTROPY) >>> ranker.SetBiasList((1,)) >>> for i,bv in enumerate(bvs): ranker.AccumulateVotes(bv,acts[i]) ... >>> for bit,gain,n0,n1 in ranker.GetTopN(3): print(int(bit),'%.3f'%gain,int(n0),int(n1)) ... 2 1.000 0 2 0 0.311 0 1 1 0.000 1 1
A chi squared ranker is also available:
>>> ranker = InfoBitRanker(4,2,InfoTheory.InfoType.CHISQUARE) >>> for i,bv in enumerate(bvs): ranker.AccumulateVotes(bv,acts[i]) ... >>> for bit,gain,n0,n1 in ranker.GetTopN(3): print(int(bit),'%.3f'%gain,int(n0),int(n1)) ... 3 4.000 2 0 2 4.000 0 2 0 1.333 0 1
As is a biased chi squared:
>>> ranker = InfoBitRanker(4,2,InfoTheory.InfoType.BIASCHISQUARE) >>> ranker.SetBiasList((1,)) >>> for i,bv in enumerate(bvs): ranker.AccumulateVotes(bv,acts[i]) ... >>> for bit,gain,n0,n1 in ranker.GetTopN(3): print(int(bit),'%.3f'%gain,int(n0),int(n1)) ... 2 4.000 0 2 0 1.333 0 1 1 0.000 1 1
- AccumulateVotes(self, bitVect: object, label: int) None¶
Accumulate the votes for all the bits turned on in a bit vector
- Parameters:
bv (-) – bit vector either ExplicitBitVect or SparseBitVect operator
label (-) – the class label for the bit vector. It is assumed that 0 <= class < nClasses
- GetTopN(self, num: int) numpy.ndarray[dtype=float64, shape=(*, *)]¶
Returns the top n bits ranked by the information metric This is actually the function where most of the work of ranking is happening
- Parameters:
num (-) – the number of top ranked bits that are required
- SetBiasList(self, classList: collections.abc.Iterable) None¶
Set the classes to which the entropy calculation should be biased
This list contains a set of class ids used when in the BIASENTROPY mode of ranking bits. In this mode, a bit must be correlated higher with one of the biased classes than all the other classes. For example, in a two class problem with actives and inactives, the fraction of actives that hit the bit has to be greater than the fraction of inactives that hit the bit
- Parameters:
classList (-) – list of class ids that we want a bias towards