1
2
3
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
17 """
18
19 """
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
49 if val and isinstance(sig,VectCollection):
50
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
61