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
13 from rdkit.DataStructs.VectCollection import VectCollection
14 import copy
15
16
18 """
19
20 """
21
24
26 """ Recursively classify an example by running it through the tree
27
28 **Arguments**
29
30 - example: the example to be classified, a sequence at least
31 2 long:
32 ( id, sig )
33 where sig is a BitVector (or something supporting __getitem__)
34 additional fields will be ignored.
35
36 - appendExamples: if this is nonzero then this node (and all children)
37 will store the example
38
39 **Returns**
40
41 the classification of _example_
42
43 """
44 if appendExamples:
45 self.examples.append(example)
46 if self.terminalNode:
47 return self.label
48 else:
49 sig = example[1]
50 val = sig[self.label]
51
52 if val and isinstance(sig, VectCollection):
53
54 sig = copy.copy(sig)
55 sig.DetachVectsNotMatchingBit(self.label)
56 ex = [example[0], sig]
57 if len(example) > 2:
58 ex.extend(example[2:])
59 example = ex
60 return self.children[val].ClassifyExample(example, appendExamples=appendExamples)
61
64