Example #1
0
    def _setupTree1a(self):
        examples1 = [['p1', 0, 1, 0.1, 4.0, 0], ['p2', 0, 0, 0.1, 4.1, 1],
                     ['p3', 0, 0, 1.1, 4.2, 2], ['p4', 0, 1, 1.1, 4.2, 2],
                     ['p5', 1, 0, 0.1, 4.2, 2], ['p6', 1, 0, 1.1, 4.2, 2],
                     ['p7', 1, 1, 0.1, 4.2, 2], ['p8', 1, 1, 1.1, 4.0, 0]]
        attrs = range(1, len(examples1[0]) - 1)
        nPossibleVals = [0, 2, 2, 0, 0, 3]
        boundsPerVar = [0, 0, 0, 1, -1, 0]

        self.t1 = BuildQuantTree.QuantTreeBoot(examples1, attrs, nPossibleVals,
                                               boundsPerVar)
        self.examples1 = examples1
Example #2
0
 def testRecycle(self):
   """ try recycling descriptors """
   examples1 = [[3,0,0],
                [3,1,1],
                [1,0,0],
                [0,0,1],
                [1,1,0],
               ]
   attrs = range(2)
   nPossibleVals = [2,2,2]
   boundsPerVar=[1,0,0]
   self.t1 = BuildQuantTree.QuantTreeBoot(examples1,attrs,nPossibleVals,boundsPerVar,
                                          recycleVars=1)
   assert self.t1.GetLabel()==0,self.t1.GetLabel()
   assert self.t1.GetChildren()[0].GetLabel()==1
   assert self.t1.GetChildren()[1].GetLabel()==1
   assert self.t1.GetChildren()[1].GetChildren()[0].GetLabel()==0
   assert self.t1.GetChildren()[1].GetChildren()[1].GetLabel()==0
Example #3
0
 def testRandomForest(self):
   """ try random forests descriptors """
   import random
   
   random.seed(23)
   nAttrs = 100
   nPts = 10
   examples = []
   for i in range(nPts):
     descrs = [random.randint(0,1) for x in range(nAttrs)]
     act = sum(descrs) > nAttrs/2
     examples.append(descrs+[act])
   attrs = range(nAttrs)
   nPossibleVals = [2]*(nAttrs+1)
   boundsPerVar=[0]*nAttrs+[0]
   self.t1 = BuildQuantTree.QuantTreeBoot(examples,attrs,
                                          nPossibleVals,boundsPerVar,
                                          maxDepth=1,
                                          recycleVars=1,
                                          randomDescriptors=3)
   assert self.t1.GetLabel()==49,self.t1.GetLabel()
   assert self.t1.GetChildren()[0].GetLabel()==3,self.t1.GetChildren()[0].GetLabel()
   assert self.t1.GetChildren()[1].GetLabel()==54,self.t1.GetChildren()[1].GetLabel()
Example #4
0
 def test8RandomForest(self):
     """ try random forests descriptors """
     import random
     random.seed(23)
     nAttrs = 100
     nPts = 10
     examples = []
     for i in range(nPts):
         descrs = [int(random.random() > 0.5) for x in range(nAttrs)]
         act = sum(descrs) > nAttrs / 2
         examples.append(descrs + [act])
     attrs = list(range(nAttrs))
     nPossibleVals = [2] * (nAttrs + 1)
     boundsPerVar = [0] * nAttrs + [0]
     self.t1 = BuildQuantTree.QuantTreeBoot(examples,
                                            attrs,
                                            nPossibleVals,
                                            boundsPerVar,
                                            maxDepth=1,
                                            recycleVars=1,
                                            randomDescriptors=3)
     self.assertEqual(self.t1.GetLabel(), 49)
     self.assertEqual(self.t1.GetChildren()[0].GetLabel(), 3)
     self.assertEqual(self.t1.GetChildren()[1].GetLabel(), 54)
Example #5
0
 def test_exampleCode(self):
     f = StringIO()
     with redirect_stdout(f):
         BuildQuantTree.TestTree()
     self.assertIn('Var: 2', f.getvalue())