示例#1
0
 def test2ranker(self):
     nbits = 100
     ninst = 100
     dm = 50
     nact = 10
     nc = 2
     RDRandom.seed(23)
     rn = rdit.InfoBitRanker(nbits, nc, rdit.InfoType.ENTROPY)
     rn.SetMaskBits([63, 70, 15, 25, 10])
     fps = []
     na = 0
     ni = 0
     for i in range(ninst):
         v = DataStructs.SparseBitVect(nbits)
         for j in range(dm):
             v.SetBit(RDRandom.randrange(0, nbits))
         if (RDRandom.randrange(0, ninst) < nact):
             na += 1
             rn.AccumulateVotes(v, 1)
             fps.append((v, 1))
         else:
             ni += 1
             rn.AccumulateVotes(v, 0)
             fps.append((v, 0))
     res = rn.GetTopN(5)
     ids = [int(x[0]) for x in res]
     ids.sort()
     self.assertTrue(ids == [10, 15, 25, 63, 70])
     with self.assertRaisesRegexp(Exception, ""):
         res = rn.GetTopN(10)
示例#2
0
 def test2ranker(self):
   nbits = 100
   ninst = 100
   dm = 50
   nact = 10
   nc = 2
   RDRandom.seed(23)
   rn = rdit.InfoBitRanker(nbits, nc, rdit.InfoType.ENTROPY)
   rn.SetMaskBits([63, 70, 15, 25, 10])
   fps = []
   na = 0
   ni = 0
   for i in range(ninst):
     v = DataStructs.SparseBitVect(nbits)
     for j in range(dm):
       v.SetBit(RDRandom.randrange(0, nbits))
     if (RDRandom.randrange(0, ninst) < nact):
       na += 1
       rn.AccumulateVotes(v, 1)
       fps.append((v, 1))
     else:
       ni += 1
       rn.AccumulateVotes(v, 0)
       fps.append((v, 0))
   res = rn.GetTopN(5)
   ids = [int(x[0]) for x in res]
   ids.sort()
   self.assertTrue(ids == [10, 15, 25, 63, 70])
   with self.assertRaisesRegexp(Exception, ""):
     res = rn.GetTopN(10)
示例#3
0
    def test1ranker(self) :
        nbits = 100
        ninst = 100
        dm = 50
        nact = 10
        nc = 2
        rn = rdit.InfoBitRanker(nbits, nc, rdit.InfoType.ENTROPY)
        fps = []
        na = 0
        ni = 0
        for i in range(ninst) :
            v = DataStructs.SparseBitVect(nbits)
            for j in range(dm):
                v.SetBit(RDRandom.randrange(0,nbits))

            
            if (RDRandom.randrange(0,ninst) < nact) :
                na += 1
                rn.AccumulateVotes(v, 1)
                fps.append((v,1))
            else:
                ni += 1
                rn.AccumulateVotes(v, 0)
                fps.append((v,0))
                
        res =  rn.GetTopN(50)

        rn2 = rdit.InfoBitRanker(nbits, nc)
        for fp in fps:
            rn2.AccumulateVotes(fp[0], fp[1])

        res2 = rn2.GetTopN(50)
        self.assertTrue((res==res2).all())
        
        rn3 = rdit.InfoBitRanker(nbits, nc, rdit.InfoType.BIASENTROPY)
        #rn3.SetBiasList([0])
        for fp in fps:
            rn3.AccumulateVotes(fp[0], fp[1])

        res3 = rn3.GetTopN(50)
        for i in range(50) :
            fan = res3[i,2]/na
            fin = res3[i,3]/ni
            self.assertTrue(fan > fin)
示例#4
0
    def test1ranker(self):
        nbits = 100
        ninst = 100
        dm = 50
        nact = 10
        nc = 2
        rn = rdit.InfoBitRanker(nbits, nc, rdit.InfoType.ENTROPY)
        fps = []
        na = 0
        ni = 0
        for i in range(ninst):
            v = DataStructs.SparseBitVect(nbits)
            for j in range(dm):
                v.SetBit(RDRandom.randrange(0, nbits))

            if (RDRandom.randrange(0, ninst) < nact):
                na += 1
                rn.AccumulateVotes(v, 1)
                fps.append((v, 1))
            else:
                ni += 1
                rn.AccumulateVotes(v, 0)
                fps.append((v, 0))

        res = rn.GetTopN(50)

        rn2 = rdit.InfoBitRanker(nbits, nc)
        for fp in fps:
            rn2.AccumulateVotes(fp[0], fp[1])

        res2 = rn2.GetTopN(50)
        self.assertTrue((res == res2).all())

        rn3 = rdit.InfoBitRanker(nbits, nc, rdit.InfoType.BIASENTROPY)
        #rn3.SetBiasList([0])
        for fp in fps:
            rn3.AccumulateVotes(fp[0], fp[1])

        res3 = rn3.GetTopN(50)
        for i in range(50):
            fan = res3[i, 2] / na
            fin = res3[i, 3] / ni
            self.assertTrue(fan > fin)