Esempio n. 1
0
def base64_to_bfp(b64):
    packed = [ord(c) for c in b64.decode("base64")]
    unpacked = ''.join('{:08b}'.format(i) for i in packed)
    n = len(unpacked)
    on_bits = [idx for idx, val in enumerate(unpacked) if val == '1']
    bfp = ExplicitBitVect(n)
    bfp.SetBitsFromList(on_bits)
    return bfp
Esempio n. 2
0
  def test2(self):
    t1 = self.tree
    vc = VectCollection()

    bv = ExplicitBitVect(5)
    bv.SetBitsFromList([0])
    vc.AddVect(1,bv)

    bv = ExplicitBitVect(5)
    bv.SetBitsFromList([1,2])
    vc.AddVect(2,bv)

    ex = ['nm',bv,1]
    self.assertTrue(t1.ClassifyExample(ex))
    
    bv = ExplicitBitVect(5)
    bv.SetBitsFromList([0,2])
    vc.AddVect(1,bv)
    ex = ['nm',bv,1]
    self.assertFalse(t1.ClassifyExample(ex))
Esempio n. 3
0
def pandas_series_to_bv(s):
    bv = ExplicitBitVect(len(s))
    on_bits = np.where(s >= True)[0].tolist()
    bv.SetBitsFromList(on_bits)
    return bv