Package rdkit :: Package ML :: Package DecTree :: Module SigTree
[hide private]
[frames] | no frames]

Source Code for Module rdkit.ML.DecTree.SigTree

 1  # 
 2  #  Copyright (C) 2003-2005  Rational Discovery LLC 
 3  #   All Rights Reserved 
 4  # 
 5  """ Defines the class SigTreeNode, used to represent trees that 
 6   use signatures (bit vectors) to represent data.  As inputs (examples), 
 7   SigTreeNode's expect 3-sequences: (label,sig,act) 
 8   
 9    _SigTreeNode_ is derived from _DecTree.DecTreeNode_ 
10   
11  """ 
12  from rdkit.ML.DecTree import DecTree,Tree 
13  from rdkit.DataStructs.VectCollection import VectCollection 
14  import copy 
15   
16 -class SigTreeNode(DecTree.DecTreeNode):
17 """ 18 19 """
20 - def NameModel(self,*args,**kwargs):
21 pass
22 - def ClassifyExample(self,example,appendExamples=0):
23 """ Recursively classify an example by running it through the tree 24 25 **Arguments** 26 27 - example: the example to be classified, a sequence at least 28 2 long: 29 ( id, sig ) 30 where sig is a BitVector (or something supporting __getitem__) 31 additional fields will be ignored. 32 33 - appendExamples: if this is nonzero then this node (and all children) 34 will store the example 35 36 **Returns** 37 38 the classification of _example_ 39 40 """ 41 if appendExamples: 42 self.examples.append(example) 43 if self.terminalNode: 44 return self.label 45 else: 46 sig = example[1] 47 val = sig[self.label] 48 #print 'val:',val 49 if val and isinstance(sig,VectCollection): 50 # we need to copy and modify the example: 51 sig = copy.copy(sig) 52 sig.DetachVectsNotMatchingBit(self.label) 53 ex = [example[0],sig] 54 if len(example)>2: 55 ex.extend(example[2:]) 56 example = ex 57 return self.children[val].ClassifyExample(example,appendExamples=appendExamples)
58
59 - def __init__(self,*args,**kwargs):
60 DecTree.DecTreeNode.__init__(self,*args,**kwargs)
61