Exemple #1
0
    def interpolateAndReturnLogBeta(self, N, gamma, currSmallest=0):
        #TODO: redesign API so that only this method and a few other similar ones are exposed.
        if not self.eta:
            raise ValueError(
                "Eta must be defined prior to interpolating and returning log beta"
            )

            #check against currSmallest
        #test case: N=150, gamma=0.01
        leftNVal = iP.find_ge(self.NList, N)[0]  #200
        if leftNVal is self.NList[-1]:
            rightNVal = leftNVal
        else:
            rightNVal = iP.find_gt(self.NList, leftNVal)[0]  #300
        rightNIndex = self.NFirstIndexHash[rightNVal]  #20
        leftNIndex = self.NFirstIndexHash[leftNVal]  #40
        clampedGamma = max(
            gamma, self.betasByAscendingNAscendingGamma['gamma'][leftNIndex])
        clampedGamma = min(
            clampedGamma,
            self.betasByAscendingNAscendingGamma['gamma'][rightNIndex])
        candidateSmallerLogBeta = np.log(
            self.betasByAscendingNAscendingGamma['beta'][iP.find_le_withBounds(
                self.betasByAscendingNAscendingGamma['gamma'], clampedGamma,
                leftNIndex, rightNIndex)[1]])
        if candidateSmallerLogBeta > currSmallest:
            return currSmallest
        return min(
            currSmallest,
            self.interpolateAndReturnLogBetaWithoutChecking(
                N, gamma))  #TODO: write wrapper function that mins this with 0
Exemple #2
0
    def interpolateAndReturnLogBeta(self, N, gamma, currSmallest=0):
    #TODO: redesign API so that only this method and a few other similar ones are exposed.
        if not self.eta:
            raise ValueError("Eta must be defined prior to interpolating and returning log beta")

            #check against currSmallest
        #test case: N=150, gamma=0.01
        leftNVal = iP.find_ge(self.NList,N)[0]  #200
        if leftNVal is self.NList[-1]:
            rightNVal = leftNVal
        else:
            rightNVal = iP.find_gt(self.NList, leftNVal)[0] #300
        rightNIndex = self.NFirstIndexHash[rightNVal]  #20
        leftNIndex = self.NFirstIndexHash[leftNVal]   #40
        clampedGamma = max(gamma, self.betasByAscendingNAscendingGamma['gamma'][leftNIndex])
        clampedGamma = min(clampedGamma, self.betasByAscendingNAscendingGamma['gamma'][rightNIndex])
        candidateSmallerLogBeta = np.log(self.betasByAscendingNAscendingGamma['beta'][iP.find_le_withBounds(
            self.betasByAscendingNAscendingGamma['gamma'], clampedGamma, leftNIndex, rightNIndex)[1]])
        if candidateSmallerLogBeta > currSmallest:
            return currSmallest
        return min(currSmallest, self.interpolateAndReturnLogBetaWithoutChecking(N, gamma))  #TODO: write wrapper function that mins this with 0
    def test_fine_le_withBounds(self):
		a=[1,2,3,4,1,2,3,4,1,2,3,4]
		x=2.6
		self.failUnlessEqual(iP.find_le_withBounds(a, x,4,8),(2,6))
 def test_fine_le_withBounds(self):
     a = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
     x = 2.6
     self.failUnlessEqual(iP.find_le_withBounds(a, x, 4, 8), (2, 6))