Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
16 changes: 8 additions & 8 deletions BBChop/source/BBChop.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def greedyStrat(counts,locPrior,likelihoodsObj,dag,skipProbs):
# test where expected entropy is smallest

expectedGain = [(currEntropy-entropyResults[i])*(numberType.one-skipProbs[i]) for
i in xrange(len(entropyResults))]
i in range(len(entropyResults))]
(next,nextp)=findMax(expectedGain)

return next
Expand All @@ -58,7 +58,7 @@ def greedyStrat(counts,locPrior,likelihoodsObj,dag,skipProbs):
# would be expected to improve next gain in entropy.

def nearlyGreedyStrat(counts,locPrior,likelihoodsObj,dag,skipProbs):
dlocs=[i for i in xrange(len(counts)) if counts[i][1]]
dlocs=[i for i in range(len(counts)) if counts[i][1]]
(currEntropy,entropyResults,findProbs)=entropiesFast(counts,locPrior,likelihoodsObj,dag)
(next,nextE)=findMin(entropyResults)
if len(dlocs):
Expand Down Expand Up @@ -140,16 +140,16 @@ def addResult(self,location,observation):
self.counts[location]=(t+1,d)

if debug:
print "ct",self.counts
print("ct",self.counts)


def search(self):
(locProbs,evProb)=self.likelihoodsObj.probs(self.counts,self.locPrior,self.dag)

(whereabouts,maxp) = findMax(locProbs)
if debug:
print "lp",map(float,locProbs)
print "ct",self.counts
print("lp",list(map(float,locProbs)))
print("ct",self.counts)
while(maxp<self.certainty):
#decide where to seach next

Expand All @@ -174,9 +174,9 @@ def search(self):


if debug:
print "lp",map(float,locProbs)
print "e",float(entropy(locProbs)),map(float,entropyResults)
print "fp",map(float,findProbs)
print("lp",list(map(float,locProbs)))
print("e",float(entropy(locProbs)),list(map(float,entropyResults)))
print("fp",list(map(float,findProbs)))

(whereabouts,maxp) = findMax(locProbs)

Expand Down
58 changes: 29 additions & 29 deletions BBChop/source/bbchop
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ options_long = [
]

def usage():
print """
print("""
bbchop is a binary search program that works in the presense of false negatives.

bbchop -l <locations> -c <certainty> [<options>]
Expand Down Expand Up @@ -90,7 +90,7 @@ bbchop -i <file> -c <certainty> [<options>]
it is an arithmetic decay factor.


"""
""")


def checkarg(arg,checkfunc):
Expand All @@ -108,7 +108,7 @@ likelihoodSet={"singlerate": likelihoods.singleRateCalc,

def getIdentifiers(fname):
try:
f=file(fname,"r")
f=open(fname,"r")

res=[l.strip() for l in f]
if len(res)==0:
Expand All @@ -119,10 +119,10 @@ def getIdentifiers(fname):
return None # caller must deal with error

def getPrior(fname,N):
f=file(fname,"r")
f=open(fname,"r")
prior=[float(l) for l in f]
if len(prior)!=N:
raise "Wrong number of entries in prior file"
raise Exception("Wrong number of entries in prior file")
return prior


Expand Down Expand Up @@ -203,17 +203,17 @@ class Args:

if identifiersFilename is not None:
if ancestryFilename is not None:
print "specification of ancestry and indentifiers are incompatible"
print "(identifiers are in ancestry file anyway)"
print("specification of ancestry and indentifiers are incompatible")
print("(identifiers are in ancestry file anyway)")
sys.exit(1)
self.identifiers=getIdentifiers(identifiersFilename)
if self.identifiers is None:
print "failed to read identifiers\n"
print("failed to read identifiers\n")
usage()
sys.exit()

if ancestryFilename is not None:
f=file(ancestryFilename,"r")
f=open(ancestryFilename,"r")
(self.identifiers,parents)=dagRead.read(f)
f.close()
self.thisDag=dag.dag(parents,len(parents))
Expand All @@ -223,27 +223,27 @@ class Args:



if likelihoodSet.has_key(self.likelihoodCalc.lower()):
if self.likelihoodCalc.lower() in likelihoodSet:
self.likelihoodCalc=likelihoodSet[self.likelihoodCalc.lower()]
else:
print "Argument error: Unknown likelihood function\n"
print("Argument error: Unknown likelihood function\n")
usage()
sys.exit()


if self.logFileName is None and self.resume:
print "cannot resume: no logfile specified\n"
print("cannot resume: no logfile specified\n")
usage()
sys.exit
sys.exit()

if self.locations is None and self.identifiers is None:
print "Argument error: Must specify number of locations or file of identifiers\n"
print("Argument error: Must specify number of locations or file of identifiers\n")
usage()
sys.exit(1)
elif self.locations is None:
self.locations=len(self.identifiers)
elif self.identifiers is None:
self.identifiers=[repr(i) for i in range(self.locations)]
self.identifiers=[repr(i) for i in list(range(self.locations))]

if distPriorFilename is not None:
self.prior=getPrior(distPriorFilename,len(self.identifiers))
Expand All @@ -252,7 +252,7 @@ class Args:


if self.certainty is None:
print "Argument error: Must specify termination certainty\n"
print("Argument error: Must specify termination certainty\n")
usage()
sys.exit(1)

Expand All @@ -275,7 +275,7 @@ class Args:
def getPrior(self):
#if specified, prior is loaded in parseArgs(). Otherwise, uniform default is set here.
if self.prior is None:
return [ 1/float(self.locations) for i in range(self.locations)]
return [ 1/float(self.locations) for i in list(range(self.locations))]
else:
return self.prior

Expand Down Expand Up @@ -312,16 +312,16 @@ class runClass:
if os.WIFEXITED(retval):
code=os.WEXITSTATUS(retval)
if code!=0:
raise "switch script (%s) exited with code %d \n" % (cmd,code)
raise Exception("switch script (%s) exited with code %d \n" % (cmd,code))
else:
raise "switch script (%s) did not exit normally\n" % (cmd)
raise Exception("switch script (%s) did not exit normally\n" % (cmd))



def statusCallback(self,ended,mostLikely,mostLikelyProb,probs,counts):
if ended:
print "\nSearch complete. ",
print "Most likely location is %s (probability %f)." % (self.identifiers[mostLikely],mostLikelyProb)
print("\nSearch complete. ", end=' ')
print("Most likely location is %s (probability %f)." % (self.identifiers[mostLikely],mostLikelyProb))


# assumes unix return code from script
Expand All @@ -346,9 +346,9 @@ class scriptTest(runClass):
elif code>0 and code<=127:
ret= True
else:
raise "unknown exit code from (%s) = %d\n" % (cmd,code)
raise Exception("unknown exit code from (%s) = %d\n" % (cmd,code))
else:
raise "test script (%s) did not exit normally\n" % (cmd)
raise Exception("test script (%s) did not exit normally\n" % (cmd))

self.logger.log(where,ret)
return ret
Expand All @@ -358,11 +358,11 @@ class scriptTest(runClass):
class manualTest(runClass):
def test(self,where):
self.switch(where)
print "Please test at location %s." % self.identifiers[where]
print("Please test at location %s." % self.identifiers[where])
prompt="Target detected at %s? Y/N/S(kip) " % self.identifiers[where]

while True:
instr=raw_input(prompt)
instr=input(prompt)
if instr in ['Y','y']:
ret= True
break
Expand Down Expand Up @@ -415,12 +415,12 @@ if args.doResume():
where=finder.search()
logger.close()

print "Number of tests at %s: %d of which %d detected" %(identifiers[where],sum(finder.counts[where]),finder.counts[where][1])
print("Number of tests at %s: %d of which %d detected" %(identifiers[where],sum(finder.counts[where]),finder.counts[where][1]))

if len(thisDag.getParents(where))>0:
print "Number of tests at parents of %s:" % (identifiers[where])
print("Number of tests at parents of %s:" % (identifiers[where]))
for p in thisDag.getParents(where):
print "\t At %s, %d of which %d detected" %(identifiers[p],sum(finder.counts[p]),finder.counts[p][1])
print("\t At %s, %d of which %d detected" %(identifiers[p],sum(finder.counts[p]),finder.counts[p][1]))
else:
print "Location %s has no parents" %(identifiers[where])
print("Location %s has no parents" %(identifiers[where]))

14 changes: 7 additions & 7 deletions BBChop/source/cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def doCalc(self,values,comb,nil):

temp=copy.copy(values)

for i in xrange(self.numVals,len(self.subExps)):
for i in range(self.numVals,len(self.subExps)):
if self.subExps[i] is None:
temp.append(values[i])
elif self.subExps[i] is -1:
elif self.subExps[i] == -1:
temp.append(nil)
else:
(a,b)=self.subExps[i]
Expand Down Expand Up @@ -110,15 +110,15 @@ def getExp(self,l):
a=nl[0]
b=nl[1]
if (a[virt]+1) == b[virt] and not (a[virt]&1):
next.append((a[virt]/2,self.getBinaryExp(a[loc],b[loc])))
next.append((a[virt]//2,self.getBinaryExp(a[loc],b[loc])))
nl.popleft()
nl.popleft()
else:
next.append((a[virt]/2,a[loc]))
next.append((a[virt]//2,a[loc]))
nl.popleft()
while len(nl)>0:
a=nl[0]
next.append((a[virt]/2,a[loc]))
next.append((a[virt]//2,a[loc]))
nl.popleft()


Expand All @@ -130,7 +130,7 @@ def getExp(self,l):
# given a list of expressions, return an object which can calculate them

def getExpList(self,expList):
return expListCalc([ self.getExp(toSortedList(expList[i])) for i in xrange(len(expList))],self)
return expListCalc([ self.getExp(toSortedList(expList[i])) for i in range(len(expList))],self)


# This object holds the locations of the wanted expressions in the temporary
Expand All @@ -149,7 +149,7 @@ def __init__(self,expList,cse):

def doCalc(self,values,comb,nil):
temp=self.cse.doCalc(values,comb,nil)
res = [temp[self.expList[i]] for i in xrange(len(self.expList))]
res = [temp[self.expList[i]] for i in range(len(self.expList))]
return res


Expand Down
26 changes: 13 additions & 13 deletions BBChop/source/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,26 @@ def findCover(soFar,covered,node,parents):

class dagX(absDag):
def __init__(self,parents,N):
print "Analysing DAG structure...",
print("Analysing DAG structure...", end=' ')
sys.stdout.flush()
self.parents=parents

children=[[] for i in xrange(N)]
children=[[] for i in range(N)]


for i in xrange(N):
for i in range(N):
for p in parents[i]:
children[p].append(i)

self.children=children

# a linear stretch ends if a node has multiple children or its child has multiple parents
self.linearEnd= [len(children[i])!=1 or len(parents[children[i][0]])!=1 for i in xrange(N)]
self.linearEnd= [len(children[i])!=1 or len(parents[children[i][0]])!=1 for i in range(N)]
# a linear stretch starts if a node has multiple parents or its parent has multiple children
self.linearStart=[len(parents[i])!=1 or len(children[parents[i][0]])!=1 for i in xrange(N)]
self.linearStart=[len(parents[i])!=1 or len(children[parents[i][0]])!=1 for i in range(N)]

loc=[set([i]) for i in xrange(N)]
empty=[set() for i in xrange(N)]
loc=[set([i]) for i in range(N)]
empty=[set() for i in range(N)]
locE=listCond(self.linearEnd,loc,empty)
locS=listCond(self.linearStart,loc,empty)

Expand All @@ -134,7 +134,7 @@ def __init__(self,parents,N):
self.AfterExpr = self.cseAfter.getExpList(self.multiAfter)


print "done"
print("done")
# The 'unique' versions of the methods do not assume that the combination function is idempotent.

def combUptoUnique(self,values,comb):
Expand All @@ -158,7 +158,7 @@ def combAfterUnique(self,values,comb):
def combUptoLinear(self,values,comb):
res=[comb([])]*len(values)

for i in xrange(len(values)):
for i in range(len(values)):
if not self.linearStart[i]:
res[i]=comb([comb([values[j],res[j]]) for j in self.parents[i]])
return res
Expand All @@ -167,7 +167,7 @@ def combUptoLinear(self,values,comb):
def combAfterLinear(self,values,comb):
res=[comb([])]*len(values)

for i in reversed(xrange(len(values))):
for i in reversed(range(len(values))):
if not self.linearEnd[i]:
res[i]=comb([comb([values[j],res[j]]) for j in self.children[i]])
return res
Expand Down Expand Up @@ -198,7 +198,7 @@ def getParents(self,loc):
def combUpto(self,values,comb):
res=[comb([])]*len(values)

for i in xrange(len(values)):
for i in range(len(values)):
res[i]=comb([comb([values[j],res[j]]) for j in self.parents[i]])
return res

Expand All @@ -207,7 +207,7 @@ def combUpto(self,values,comb):
def combAfter(self,values,comb):
res=[comb([])]*len(values)

for i in reversed(xrange(len(values))):
for i in reversed(range(len(values))):
res[i]=comb([comb([values[j],res[j]]) for j in self.children[i]])
return res

Expand Down Expand Up @@ -278,7 +278,7 @@ def sumOther(self,values):


def linearTestDag(N):
parents=['%d %d' %(a+1,a) for a in xrange(N-1)]
parents=['%d %d' %(a+1,a) for a in range(N-1)]
parents[:0]='0'
return dag(parents,N)

Expand Down
2 changes: 1 addition & 1 deletion BBChop/source/dagRead.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def read(inputFile):

# which node id is where
dagLocs={}
for i in xrange(len(identifiers)):
for i in range(len(identifiers)):
dagLocs[identifiers[i]]=i


Expand Down
Loading