def makeStat(seed, rate=None, minRate=None, maxRate=None, N=None, prior=None, cert=None, likelihoodObj=None, dagObj=None, counts=None): if rate is None: if minRate is None: minRate = 0.0 if maxRate is None: maxRate = 1.0 rate = random.uniform(minRate, maxRate) if N is None: N = random.randint(2, maxLen) if prior is None: prior = [1 / float(N) for i in range(N)] if cert is None: db = random.uniform(3, 6) cert = 1.0 - pow(0.5, db) if dagObj is None: dagObj = dag.listDagObj tester = detect(N, rate, dagObj, dagObj is likelihoods.multiRateCalc) finder = BBChop.BBChop(prior, cert, tester, likelihoodObj, dagObj) loc = tester.loc if counts is not None: finder.restoreCheckpoint(prior, copy.copy(counts)) key = (rate, loc, N, cert, counts[-1][0], counts[-1][1], likelihoodObj.name().strip(), seed) if statDb.has_key(key): (tests, guess, right) = statDb.get(key) sys.stdout.write('.') sys.stdout.flush() else: guess = finder.search() right = (loc == guess) tests = tester.tests sys.stdout.write('#') sys.stdout.flush() statDb.add(key, (tests, guess, right)) return (rate, loc, N, cert, tests, guess, right, likelihoodObj.name(), counts[-1])
def makeStat(seed,rate=None,minRate=None,maxRate=None,N=None,prior=None,cert=None,likelihoodObj=None,dagObj=None,counts=None): if rate is None: if minRate is None: minRate=0.0 if maxRate is None: maxRate=1.0 rate=random.uniform(minRate,maxRate) if N is None: N=random.randint(2,maxLen) if prior is None: prior=[ 1/float(N) for i in range(N)] if cert is None: db=random.uniform(3,6) cert=1.0-pow(0.5,db) if dagObj is None: dagObj=dag.listDagObj tester=detect(N,rate,dagObj,dagObj is likelihoods.multiRateCalc) finder=BBChop.BBChop(prior,cert,tester,likelihoodObj,dagObj) loc=tester.loc if counts is not None: finder.restoreCheckpoint(prior,copy.copy(counts)) key=(rate,loc,N,cert,counts[-1][0],counts[-1][1],likelihoodObj.name().strip(),seed) if statDb.has_key(key): (tests,guess,right)=statDb.get(key) sys.stdout.write('.') sys.stdout.flush() else: guess=finder.search() right=(loc==guess) tests=tester.tests sys.stdout.write('#') sys.stdout.flush() statDb.add(key,(tests,guess,right)) return (rate,loc,N,cert,tests,guess,right,likelihoodObj.name(),counts[-1])
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
self.value = value isGit = os.environ["TEST_SEARCHER"] == "git" print isGit try: ancestryFilename = os.environ["TEST_ANCESTRY"] testDir = os.environ["TEST_DIR"] loc = int(os.environ["TEST_LOC"]) f = file(ancestryFilename, "r") (identifiers, parents) = dagRead.read(f) f.close() N = len(parents) thisDag = dag.dag(parents, N) t = testDetector.detect(N, 1.0, thisDag, False, loc) numbers = {} for i in range(len(identifiers)): numbers[identifiers[i]] = i if isGit: os.system("git rev-parse HEAD >$TEST_DIR/__head__") where = open(testDir + "/__head__", "r").readline().strip() where = numbers[where] else: where = sys.argv[1] where = numbers[where] os.system("echo 'foo' >>$TEST_DIR/tries")
self.value = value isGit = os.environ['TEST_SEARCHER']=='git' print isGit try: ancestryFilename=os.environ['TEST_ANCESTRY'] testDir = os.environ["TEST_DIR"] loc=int(os.environ['TEST_LOC']) f=file(ancestryFilename,"r") (identifiers,parents)=dagRead.read(f) f.close() N=len(parents) thisDag=dag.dag(parents,N) t=testDetector.detect(N,1.0,thisDag,False,loc) numbers={} for i in range(len(identifiers)): numbers[identifiers[i]]=i if isGit: os.system("git rev-parse HEAD >$TEST_DIR/__head__") where=open(testDir+"/__head__","r").readline().strip() where=numbers[where] else: where = sys.argv[1] where=numbers[where] os.system("echo 'foo' >>$TEST_DIR/tries")