def test1Cluster(self): cmg = rdInfoTheory.BitCorrMatGenerator() cmg.SetBitList(self.blist) for fp in self.fps: cmg.CollectVotes(fp) corrMat = cmg.GetCorrMatrix() bcl = BitClusterer.BitClusterer(self.blist, self.nbits // 2) bcl.ClusterBits(corrMat) cls = bcl.GetClusters() for cl in cls: self.assertEqual(len(cl), 2) self.assertEqual((cl[0] + self.nbits // 2), cl[1]) bcl.SetClusters(cls) self.assertRaises(AssertionError, bcl.SetClusters, cls[:-1]) tfp = DataStructs.ExplicitBitVect(self.nbits) obits = list(range(0, self.nbits // 4)) + list(range(self.nbits // 2, 3 * self.nbits // 4)) tfp.SetBitsFromList(obits) rvc = bcl.MapToClusterScores(tfp) self.assertEqual(len(rvc), self.nbits // 2) for i in range(self.nbits // 2): if i < self.nbits // 4: self.assertEqual(rvc[i], 2) else: self.assertEqual(rvc[i], 0) nfp = bcl.MapToClusterFP(tfp) self.assertEqual(len(nfp), self.nbits // 2) for i in range(self.nbits // 2): if i < self.nbits // 4: self.assertTrue(nfp[i]) else: self.assertFalse(nfp[i])
def test0CorrMat(self): cmg = rdInfoTheory.BitCorrMatGenerator() cmg.SetBitList(self.blist) for fp in self.fps: cmg.CollectVotes(fp) corrMat = cmg.GetCorrMatrix() avr = 0.0 navr = 0.0 for i in range(self.nbits / 2): avr += getValLTM(i, i + self.nbits / 2, corrMat) navr += getValLTM(i, i + 1, corrMat) assert 2 * avr / self.nbits == 400.0 assert 2 * navr / self.nbits == 158.3, 2 * navr / self.nbits
def test1Cluster(self): if BitClusterer is None: return cmg = rdInfoTheory.BitCorrMatGenerator() cmg.SetBitList(self.blist) for fp in self.fps: cmg.CollectVotes(fp) corrMat = cmg.GetCorrMatrix() bcl = BitClusterer.BitClusterer(self.blist, self.nbits / 2) bcl.ClusterBits(corrMat) cls = bcl.GetClusters() for cl in cls: assert len(cl) == 2 assert (cl[0] + self.nbits / 2) == cl[1] tfp = DataStructs.ExplicitBitVect(self.nbits) obits = range(0, self.nbits / 4) + range(self.nbits / 2, 3 * self.nbits / 4) tfp.SetBitsFromList(obits) rvc = bcl.MapToClusterScores(tfp) assert len(rvc) == self.nbits / 2 for i in range(self.nbits / 2): if i < self.nbits / 4: assert rvc[i] == 2 else: assert rvc[i] == 0 nfp = bcl.MapToClusterFP(tfp) assert len(nfp) == self.nbits / 2 for i in range(self.nbits / 2): if i < self.nbits / 4: assert nfp[i] else: assert not nfp[i]