def getBinEfficiencies(self, binnr): binmid = generateBinMid(self.myrange, binnr, self.RBins, self.RRange[0]) myR0 = self.getR0(binnr) reff = rToEff(binmid, myR0) print "Bin efficiency is %6.4f" % reff return [reff] * self.BurstCount, getBurstSizes(self.BurstCount, self.burstGenerator)
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)
def testGlobalShotNoise(self): for sn, sng in ((5, self.constant5Burstgen), (50, self.constant50Burstgen), (500, self.constant500Burstgen), (5000, self.constant5000Burstgen)): tm = GlobalAVGKappaTransferMatrix(20, 11, 1000, sng, 5.475, (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)
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)
def getBinEfficiencies(self, binnr): if not self.kappaBinned: self.binKappa() bursts = getBurstSizes(self.BurstCount, self.burstGenerator) beffs = [] rkprb = np.array(self.rkappaBinned[binnr]) Rarr = rkprb[:, 0] Kappaarr = rkprb[:, 1] Prbarr = rkprb[:, 2]**0 # R0s_mod = modifyR0(self.R0, Kappaarr) # # cumulprb = Prbarr.cumsum() # cumulprb /= cumulprb[-1] # for burst in bursts: # randnrs = np.random.random(burst) # ndxchoice = cumulprb.searchsorted(randnrs) # effs = rToEff(Rarr[ndxchoice], R0s_mod[ndxchoice]) # beffs.append(effs) cumulprb = Prbarr.cumsum() cumulprb /= cumulprb[-1] for burst in bursts: randnrs = np.random.random(burst) ndxchoice = cumulprb.searchsorted(randnrs) Ravg = Rarr[ndxchoice].mean() Kavg = Kappaarr[ndxchoice].mean() R0_mod = modifyR0(self.R0, Kavg) effs = rToEff(Ravg, R0_mod) beffs.append(effs) print "%d Efficiencies for bursts in bin %d calculated from %d R-K samples" % ( len(beffs), binnr, R0_mod) return beffs, bursts
def getBinEfficiencies(self, binnr): if not self.kappaBinned: self.binKappa() bursts = getBurstSizes(self.BurstCount, self.burstGenerator) beffs = [] rkprb = np.array(self.rkappaBinned[binnr]) Rarr = rkprb[:, 0] Kappaarr = rkprb[:, 1] Prbarr = rkprb[:, 2] ** 0 # R0s_mod = modifyR0(self.R0, Kappaarr) # # cumulprb = Prbarr.cumsum() # cumulprb /= cumulprb[-1] # for burst in bursts: # randnrs = np.random.random(burst) # ndxchoice = cumulprb.searchsorted(randnrs) # effs = rToEff(Rarr[ndxchoice], R0s_mod[ndxchoice]) # beffs.append(effs) cumulprb = Prbarr.cumsum() cumulprb /= cumulprb[-1] for burst in bursts: randnrs = np.random.random(burst) ndxchoice = cumulprb.searchsorted(randnrs) Ravg = Rarr[ndxchoice].mean() Kavg = Kappaarr[ndxchoice].mean() R0_mod = modifyR0(self.R0, Kavg) effs = rToEff(Ravg, R0_mod) beffs.append(effs) print "%d Efficiencies for bursts in bin %d calculated from %d R-K samples" % (len(beffs), binnr, R0_mod) return beffs, bursts