Example #1
0
 def testDistanceAVGLocalKappaAveraging(self):
     R = numpy.concatenate((numpy.linspace(5.05, 5.95, 20), numpy.linspace(5.05, 5.95, 20), numpy.linspace(5.05, 5.95, 20)))
     kappa = [ 1.  ] * 20 + [ 1. ] * 20 + [ 0. ] * 20
     weights = [ 1. ] * 60
     tm = DistanceAVGKappaTransferMatrix(20, 11, 5, self.constant5000Burstgen, 5.475, R, kappa, weights, RRange = (5, 6))
     self.assertEqual(tm.getKappaAVG()[2], 2. / 3)
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     self.assertEqual(tm.getMatrix()[9][5], 1.)
Example #2
0
 def testDistanceAVG(self):
     R = numpy.linspace(5, 6, 1100)
     kappa = [ 2. / 3 ] * 1100
     weights = [ 1. ] * 1100
     tm = DistanceAVGKappaTransferMatrix(20, 11, 5, self.constant5000Burstgen, 5.475, R, kappa, weights)
     tm.generateMatrix()
     self.assertEqual(tm.getMatrix().shape, (20, 11))
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     self.assertEqual(tm.getMatrix()[9][5], 1.)
Example #3
0
 def testSamplesOutsideRange(self):
     R = numpy.linspace(4.95, 6.05, 22)
     kappa = [ 2. / 3 ] * 22
     weights = [ 1. ] * 22
     tm = DistanceAVGKappaTransferMatrix(20, 11, 200, self.constant5000Burstgen, 5.475, R, kappa, weights, RRange = (5., 6))
     tm.generateMatrix()
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     self.assertAlmostEqual(tm.getMatrix()[9][5], 1., delta = 0.01)
     tmref = GlobalAVGKappaTransferMatrix(20, 11, 200, self.constant5000Burstgen, 5.475, (5, 6))
     self.assertMatrixAlmostEqual(tm.getMatrix() , tmref.getMatrix(), delta = 0.15)
Example #4
0
 def testDistanceAVGLocalKappavsGlobal(self):
     R = numpy.linspace(5.05, 5.95, 20)
     kappa = [ 2. / 3 ] * 20
     weights = [ 1. ] * 20
     tm = DistanceAVGKappaTransferMatrix(20, 11, 5000, self.constant5000Burstgen, 5.475, R, kappa, weights, RRange = (5, 6))
     tm.generateMatrix()
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     self.assertAlmostEqual(tm.getMatrix()[9][5], 1., delta = 0.01)
     tmref = GlobalAVGKappaTransferMatrix(20, 11, 5000, self.constant5000Burstgen, 5.475, [5, 6])
     self.assertMatrixAlmostEqual(tm.getMatrix(), tmref.getMatrix(), delta = 0.05)
Example #5
0
 def testDistanceAVGAlteredKappa(self):
     R = numpy.linspace(5, 6, 1100)
     kappa = [ 2. / 3 ] * 200 + [ 1. / 3 ] * 400 + [ 2. / 3 ] * 500
     weights = [ 1. ] * 1100
     tm = DistanceAVGKappaTransferMatrix(20, 11, 5, self.constant5000Burstgen, 5.475, R, kappa, weights)
     tm.generateMatrix()
     self.assertEqual(tm.getMatrix().shape, (20, 11))
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     R0neu = modifyR0(5.475, 1. / 3)
     print "New R0 is %f" % R0neu
     eff = rToEff(5.475, R0 = R0neu)
     effndx = int(eff * 11)
     self.assertAlmostEqual(tm.getMatrix()[9][effndx], 1, delta = 0.01)
Example #6
0
 def testRandomUncorr(self):
     length = 100000
     startdist = 4
     enddist = 7
     rbins = 10
     ebins = 20
     bursts = 10000
     R0 = 5.475
     bgen = self.constant50Burstgen
     R = numpy.random.random(length) * (enddist - startdist) + startdist
     kappa2 = numpy.array(list(getKappa(genRandomVec(), genRandomVec(), genRandomVec()) ** 2 for _ in range(length)))
     print "Kappa^2 mean is ", kappa2.mean()
     R0mod = modifyR0(R0, kappa2.mean())
     prbs = numpy.ones(length)
     globaltm = GlobalAVGKappaTransferMatrix(rbins, ebins, bursts, bgen, R0mod, (startdist, enddist))
     localtm = DistanceAVGKappaTransferMatrix(rbins, ebins, bursts, bgen, R0, R, kappa2, prbs, RRange = (startdist, enddist))
     self.assertMatrixAlmostEqual(globaltm.getMatrix(), localtm.getMatrix(), delta = 0.10)
Example #7
0
 def testDistanceAVGShotNoise(self):
     R = numpy.linspace(5, 6, 1100)
     kappa = [ 2. / 3 ] * 1100
     weights = [ 1. ] * 1100
     for sn, sng in ((5, self.constant5Burstgen), (50, self.constant50Burstgen), (500, self.constant500Burstgen), (5000, self.constant5000Burstgen)):
         tm = DistanceAVGKappaTransferMatrix(20, 11, 1000, sng, 5.475, R, kappa, weights, RRange = (5, 6))
         tmx = tm.getMatrix()
         print "Burstsizes %d" % sn
         for _ in range(7):
             mbin = random.choice(range(20))
             binmid = generateBinMid(1, mbin, 20, 5)
             eff = rToEff(binmid, R0 = 5.475)
             print "Testing mbin %d at pos %f with efficiency %f" % (mbin, binmid, eff)
             shotnoise = getShotNoise(eff, 11, 1000, sn)
             tmxvec = tmx[mbin, :]
             tmxvec.shape = (11, 1)
             self.assertAlmostEqual((tmxvec - shotnoise).sum(), 0.0, delta = 0.005)