rdkit.ML.DecTree.SigTree

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
    13  from rdkit.DataStructs.VectCollection import VectCollection
    14  import copy
    15
    16
    17 -class SigTreeNode(DecTree.DecTreeNode):
    18    """
    19
    20    """
    21
    22 -  def NameModel(self, *args, **kwargs):
    23      pass
    24
    25 -  def ClassifyExample(self, example, appendExamples=0):
    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        # print 'val:',val
    52        if val and isinstance(sig, VectCollection):
    53          # we need to copy and modify the example:
    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
    62 -  def __init__(self, *args, **kwargs):
    63      DecTree.DecTreeNode.__init__(self, *args, **kwargs)
    64