本文整理汇总了Python中Population.Population.calcNumDied方法的典型用法代码示例。如果您正苦于以下问题:Python Population.calcNumDied方法的具体用法?Python Population.calcNumDied怎么用?Python Population.calcNumDied使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population.Population
的用法示例。
在下文中一共展示了Population.calcNumDied方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import calcNumDied [as 别名]
#.........这里部分代码省略.........
self.timeLog.append(timeLogFirstRow)
timeLogStartRow = [0, self.newPop.getSize(), self.newPop.getInitialSick(),
self.newPop.getInitialImmune(), 0, 0, 0]
self.timeLog.append(timeLogStartRow)
self.startTime = time.time()
self.writeInitialPop()
def runSim(self):
lowPopFlag = False
for i in range(1, self.numTimePeriods+1):
if lowPopFlag: break
newTrans = 0
numInts = int(round(self.intsPerTime * self.newPop.getSize()))
for j in range(1,numInts+1):
deadCheck = True
while deadCheck:
edgeNum = random.randint(0, len(self.newPop.agents.es)-1)
randEdge = self.newPop.agents.es[edgeNum]
vert1 = self.newPop.agents.vs[randEdge.source]
vert2 = self.newPop.agents.vs[randEdge.target]
agent1 = vert1["Agent"]
agent2 = vert2["Agent"]
newInt = Interaction(agent1, agent2)
deadCheck = newInt.deadCheck()
newInt.setStartVals()
newRule = Rules([agent1, agent2])
newResult = newRule.gameResult(self.meanPosVal, self.meanAvoidVal)
if newResult[0] == "Avoid":
vert1["Agent"].updateValue(newResult[1])
vert2["Agent"].updateValue(newResult[2])
else:
newTrans = newTrans + vert1["Agent"].updateDisease(vert2["Agent"], newResult[1])
newTrans = newTrans + vert2["Agent"].updateDisease(vert1["Agent"], newResult[2])
newInt.setEndVals()
if self.logInteractions == True:
interaction = [i, j, newInt, newRule, newResult]
self.intLog.append(interaction)
self.newPop.updateSickTime()
self.newPop.updateDead()
self.totalInts = self.totalInts + numInts
self.newPop.logEnd()
R0 = self.newPop.calcRo()
newLogVals = [i, self.newPop.getSize(), self.newPop.getFinalSick(),
self.newPop.getFinalImmune(), newTrans, R0, numInts]
self.timeLog.append(newLogVals)
print('Completed time ' + str(i))
if lowPopFlag: break
newLogVals = [i, numInts, self.newPop.getFinalSick(), self.newPop.getFinalImmune(), newTrans]
self.totalInts = self.totalInts + numInts
self.timeLog.append(newLogVals)
totalDied = self.newPop.calcNumDied()
totalImmune = self.newPop.getFinalImmune()
self.runVals.append(totalDied)
self.runVals.append(totalImmune)
self.endTime = time.time()
self.runTime = round((self.endTime - self.startTime), 2)
self.timePerInt = self.runTime / self.totalInts
print('The simulation ran in ' + str(self.runTime) + ' seconds')
print('Total number of interactions simulated: ' + str(self.totalInts))
print('Effective time per interaction: ' + str(self.timePerInt))
return self
def writeInitialPop(self):
os.chdir('C:/Users/russ.clay/Desktop/Simulations/Agent/Exports')
filename = 'initialPopulationLogData_' + str(self.simNum) + '.csv'
with open(filename, 'wb') as csvfile:
datawriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
firstRow = ["ID", "Openness", "Value", "SickVal", "DeadVal",
"Disease", "DiseaseTime", "Immunity"]
datawriter.writerow(firstRow)
for i in self.newPop.agents.vs:
tempAgent = i["Agent"]
ID = tempAgent.getID()
opn = tempAgent.getOpenness()
val = tempAgent.getValue()
if tempAgent.getDisease():
sck = tempAgent.diseaseType.getSickValue()
else: sck = None
ded = tempAgent.getDeadValue()
dis = tempAgent.getDisease()
dtm = tempAgent.getDiseaseTime()
imm = tempAgent.getImmunity()
newRow = [ID, opn, val, sck, ded, dis, dtm, imm]
datawriter.writerow(newRow)
示例2: __init__
# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import calcNumDied [as 别名]
#.........这里部分代码省略.........
# if interaction logging is turned on, log the values captured during the interaction
if self.logInteractions == True:
interaction = [i, numInts, newInt, [vert1, vert2], newResult, intType]
self.intLog.append(interaction)
# print "appended interaction record to log" # debugging
# after all interactions have ocurred for the time period, update disease spread (done separately so that disease does not spread throughout the population in a single time period)
newTrans = self.updateDiseaseSpread(newTransStack)
# print "determined disease spread" # debugging
# increment the sick time for all agents who are infected with disease
self.newPop.updateSickTime()
# print "updated sick time" # debug
self.newPop.updateDead() # iterate through the population to set the status of any agents with 0 or lower health value to 'Dead'
# print "updated deceased population members" # debug
self.totalInts = self.totalInts + numInts # update the total number of interactions
# print "updated number of interactions" # debugging
# Log ending summary population statistics for the time period
self.newPop.logEnd()
# print "logged ending values for time iteration" #debugging
R0 = self.newPop.calcRo(self.timeLog[len(self.timeLog)-1][2])
# print "calculated R0 value" # debugging
self.newPop.createGraph(i)
newLogVals = [i, self.newPop.getSize(), self.newPop.getFinalSick(),
self.newPop.getFinalImmune(), newTrans, R0, numInts]
self.timeLog.append(newLogVals)
self.writeInteractions(i)
print('Completed time ' + str(i)) # debugging
# Update summary statistics after final time period
newLogVals = [i, numInts, self.newPop.getFinalSick(), self.newPop.getFinalImmune(), newTrans]
self.totalInts = self.totalInts + numInts
self.timeLog.append(newLogVals)
totalDied = self.newPop.calcNumDied()
totalImmune = self.newPop.getFinalImmune()
self.runVals.append(totalDied)
self.runVals.append(totalImmune)
self.endTime = time.time()
self.runTime = round((self.endTime - self.startTime), 2)
self.timePerInt = self.runTime / self.totalInts
# Write out completed simulation statistics to the console
print('The simulation ran in ' + str(self.runTime) + ' seconds')
print('Total number of interactions simulated: ' + str(self.totalInts))
print('Effective time per interaction: ' + str(self.timePerInt))
# return a copy off the simulation instance to main for logging
return self
# -------------------
# --- Class Functions
#--------------------
def gameResult(self, intPair, posVal, avoidVal):
if intPair[0]["Family"] == intPair[1]["Family"]:
newResult = self.famInteract(intPair, posVal, avoidVal)
else:
if intPair[0]["Group"] == intPair[1]["Group"]:
newResult = self.ingroupInteract(intPair, posVal, avoidVal)
else: newResult = self.outgroupInteract(intPair, posVal, avoidVal)
return newResult
def famInteract(self, intPair, posVal, avoidVal):
randSeed = random.uniform(0,1)