def testImpute(snpData, Ls): """ Function that slides the window(s) and calculates accuracy of imputation on all called values. """ global corrects global count L = max(Ls) vectors = snpData.vectors snps = snpData.snps numSNPs = len(snps) print "Running imputation window test with %d window sizes..." % len(Ls), count = 0 corrects = zeros(len(Ls)) vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue(Ls, vectorLength) acc = zeros((len(Ls), vectorLength), uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector for j in xrange(len(Ls)): if i < Ls[j]: add(acc[j], snpVector, acc[j]) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: vectorQueue.enqueue(vectors[snps[i + L]]) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) mid = vectorQueue.getMid() snp = snps[i] for j in xrange(len(Ls)): top, bottom = vectorQueue.getEnds(j) add(acc[j], top, acc[j]) subtract(acc[j], bottom, acc[j]) imputeSNPT(snpData, i, acc[j] - mid, snp, j) print "Done" return count, corrects
def testImpute(snpData, Ls): ''' Function that slides the window(s) and calculates accuracy of imputation on all called values. ''' global corrects global count L = max(Ls) vectors = snpData.vectors snps = snpData.snps numSNPs = len(snps) print 'Running imputation window test with %d window sizes...' % len(Ls), count = 0 corrects = zeros(len(Ls)) vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue(Ls, vectorLength) acc = zeros((len(Ls), vectorLength), uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector for j in xrange(len(Ls)): if i < Ls[j]: add(acc[j], snpVector, acc[j]) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: vectorQueue.enqueue(vectors[snps[i + L]]) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) mid = vectorQueue.getMid() snp = snps[i] for j in xrange(len(Ls)): top, bottom = vectorQueue.getEnds(j) add(acc[j], top, acc[j]) subtract(acc[j], bottom, acc[j]) imputeSNPT(snpData, i, acc[j] - mid, snp, j) print 'Done' return count, corrects
def impute(snpData, L): """ Function that slides the window and calls other functions to do the actual imputation. """ global count snpData.changes = dict() count = 0 snps = snpData.snps vectors = snpData.vectors numSNPs = len(snps) sys.stderr.write("Imputing with window size " + str(L) + "...") vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue([L], vectorLength) acc = zeros(vectorLength, uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector add(acc, snpVector, acc) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: snpVector = vectors[snps[i + L]] vectorQueue.enqueue(snpVector) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) top, bottom = vectorQueue.getEnds(0) add(acc, top, acc) subtract(acc, bottom, acc) snp = snps[i] if "?" in snp: imputeSNP(snpData, i, acc, snp) sys.stderr.write("Done.\n") return count
def impute(snpData, L): ''' Function that slides the window and calls other functions to do the actual imputation. ''' global count snpData.changes = dict() count = 0 snps = snpData.snps vectors = snpData.vectors numSNPs = len(snps) print "Imputing with window size " + str(L) + "...", vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue([L], vectorLength) acc = zeros(vectorLength, uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector add(acc, snpVector, acc) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: snpVector = vectors[snps[i + L]] vectorQueue.enqueue(snpVector) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) top, bottom = vectorQueue.getEnds(0) add(acc, top, acc) subtract(acc, bottom, acc) snp = snps[i] if '?' in snp: imputeSNP(snpData, i, acc, snp) print "Done" return count
class TicketCounterSimulation: def __init__(self, numAgents, numMinutes, betweenTime, serviceTime): self._arriveprob = 1.0 / betweenTime self._serviceTime = serviceTime self._numMinutes = numMinutes self.served = 0 self._passengers = CircularQueue() self._Agents = [None] * numAgents for i in range(numAgents): self._Agents = TicketAgent(i + 1) self._totalWaitTime = 0 self._numPassengers = 0 def run(self): for curTime in range(self._numMinutes): self._handleArrival(curTime) self._handleBeginService(curTime) self._handleEndService(curTime) self.printResult() def printResult(self): numServed = self._numPassengers - len(self._passengers) avgwait = float(self._totalWaitTime) / numServed print("") print("Number of passengers served()") print("Number of passengers remaining in line") print("The average wait time was") # Handle Customer Arrival def _handleArrival(self, curTime): prob = randint(0.0, 1.0) if 0.0 <= prob and prob <= self._arriveprob: person = Passenger(self._numPassengers + 1, curTime) self._passengers.enqueue(person) self._numPassengers += 1 print("Time Passenger") # Begin Customer Service def _handleBeginService(self, curTime): i = 0 while i < len(self._Agents): if self._Agents[i].isFree() and not self._passengers.isEmpty( ) and curTime != self._numMinutes: passenger = self._passengers.dequeue() self.served += 1 stoptime = curTime + self._serviceTime self._Agents[i].starService(passenger, stoptime) self._totalWaitTime += (curTime - passenger.timeArrivaed()) print("Time Agent started serving") # End Customer Service def _handleEndService(self, curTime): i = 0 while i < len(self._Agents): if self._Agents[i].isFinished(curTime): passenger = self._Agents[i].stopService() print(":Time Agent stoped serving") i += 1