def testChop(likelihoodObj, randomDag, falseNeg, multi): tests = 0 right = 0 wrong = [] totalLooks = 0.0 for k in range(trials): random.seed(k + 1) dagObj = testCases.testDag(N, randomDag) if falseNeg: rate = random.random() else: rate = 1 tester = detect(N, rate, dagObj, multi) finder = BBChop.BBChop(prior, cert, tester, likelihoodObj, dagObj) loc = tester.loc guess = finder.search() totalLooks += finder.total tests += tester.tests if loc == guess: right = right + 1 else: wrong.append(guess) # if((k+1)%10 == 0): print "test ", k, " right%=", 100.0 * right / (k + 1), "right=", loc == guess, "totallooks=", totalLooks / ( k + 1 ), "looks=", finder.total, "rate=", rate # if((k+1)%100 ==0): # tester.printLocs() print "right:", right, " out of", trials, tests / trials return (float(right) / trials) < cert
def testChop(likelihoodObj, randomDag, falseNeg, multi): tests = 0 right = 0 wrong = [] totalLooks = 0.0 for k in range(trials): random.seed(k + 1) dagObj = testCases.testDag(N, randomDag) if falseNeg: rate = random.random() else: rate = 1 tester = detect(N, rate, dagObj, multi) finder = BBChop.BBChop(prior, cert, tester, likelihoodObj, dagObj) loc = tester.loc guess = finder.search() totalLooks += finder.total tests += tester.tests if (loc == guess): right = right + 1 else: wrong.append(guess) #if((k+1)%10 == 0): print "test ", k, " right%=", 100.0 * right / ( k + 1), "right=", loc == guess, "totallooks=", totalLooks / ( k + 1), "looks=", finder.total, "rate=", rate #if((k+1)%100 ==0): # tester.printLocs() print "right:", right, " out of", trials, tests / trials return (float(right) / trials) < cert
def testEntropyFunc(entropyFunc1,entropyFunc2,likelihoodArg1,likelihoodArg2,falsePos=False,falseNeg=False,maxCount=10,randomDag=False): print "testing " ,entropyFunc1.func_name,entropyFunc2.func_name,likelihoodArg1.name(),likelihoodArg2.name(),"maxCount=",maxCount,"randomDag=",randomDag fail=False for t in range(tests): d=testCases.testDag(n,randomDag) (counts,locPrior)=testCases.randomEntropyData(t+1,n,d,falsePos,falseNeg,maxCount) # pdb.set_trace() (c1,e1,f1)=entropyFunc1(counts,locPrior,likelihoodArg1,d) # pdb.set_trace() (c2,e2,f2)=entropyFunc2(counts,locPrior,likelihoodArg2,d) thisFail=False if not rough_eq(c1,c2): print "Error:\t",c1,c2 thisFail=True for j in range(n): # print "entropy:\t ",j,e1[j],e2[j] #,max(e1[j]/e2[j],e2[j]/e1[j]) if not rough_eq(e1[j],e2[j]): print "Error:\t",e1[j],e2[j] thisFail=True if thisFail: fail=True print "test %d failed!" % t else: print "test %d passed" % t if fail: print "FAILED!" else: print "PASSED!" return fail
import testCases random.seed(1) mult=100 out=file("data/N_T.singleRate.csv","w") for n in range(50,1000,50): d=testCases.testDag(n,False) for i in range(mult): (counts,locPrior)=testCases.randomEntropyData(i+1,n,d,False,True,10) start=time.clock() junk=evidence.entropiesFast(counts,locPrior,likelihoods.singleRateCalc,d) end=time.clock() out.write("%d,%f\n" % (n,(end-start))) print n out.close()
# # You should have received a copy of the GNU General Public License # along with BBChop. If not, see <http://www.gnu.org/licenses/>. import evidence import time import random import likelihoods import testCases random.seed(1) mult = 100 out = file("data/N_T.singleRate.csv", "w") for n in range(50, 1000, 50): d = testCases.testDag(n, False) for i in range(mult): (counts, locPrior) = testCases.randomEntropyData(i + 1, n, d, False, True, 10) start = time.clock() junk = evidence.entropiesFast(counts, locPrior, likelihoods.singleRateCalc, d) end = time.clock() out.write("%d,%f\n" % (n, (end - start))) print n out.close()