def test_zeroWeights(self): w = [1, 0, 0, 0, 0] p = pf.generateRandomParticles(5) resampled = pf.resample(w, p) for i in resampled: print(i) self.assertEqual(i, p[0])
def test_randomPercent(self): num = 4 randPercent = [random.random()] b = (1.0 - randPercent[0]) / (num-1) restofparticles = [b for i in range(num)] w = randPercent + restofparticles p = pf.generateRandomParticles(num) count = 0 N = 1000 for i in range(N): resampled = pf.resample(w, p) count += resampled.count(p[0]) percent = count / (N * num) self.assertWithinx(percent, randPercent[0], 0.02)