当前位置: 首页>>代码示例>>Python>>正文


Python Population.getFinalImmune方法代码示例

本文整理汇总了Python中Population.Population.getFinalImmune方法的典型用法代码示例。如果您正苦于以下问题:Python Population.getFinalImmune方法的具体用法?Python Population.getFinalImmune怎么用?Python Population.getFinalImmune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Population.Population的用法示例。


在下文中一共展示了Population.getFinalImmune方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import getFinalImmune [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)
开发者ID:drRussClay,项目名称:AB_Simulation-BIS,代码行数:104,代码来源:Simulation.py

示例2: __init__

# 需要导入模块: from Population import Population [as 别名]
# 或者: from Population.Population import getFinalImmune [as 别名]

#.........这里部分代码省略.........
                    if newResult[0] == "Interact":
                        newTransStack.append(vert1["Agent"].updateDisease(vert2["Agent"]))
                        newTransStack.append(vert2["Agent"].updateDisease(vert1["Agent"]))
                        numInts+=1  # increment the number of total interactions
#                        print "Interaction...checked and logged disease spread" # debugging
                    
                    newInt.setEndVals() # log the updated health values of the agents
#                    print "ending interaction values set" # debugging
                    
                    # 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:
开发者ID:drRussClay,项目名称:Simulation,代码行数:70,代码来源:Simulation.py


注:本文中的Population.Population.getFinalImmune方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。