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


Python Population.setPop方法代码示例

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


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

示例1: __init__

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

#.........这里部分代码省略.........
    def getDisease(self):
        return self.newDisease
        
    def getPopulation(self):
        return self.newPop
        
    def getIntLog(self):
        return self.intLog
        
    def getTotalInts(self):
        return self.totalInts
        
    def getTimeLog(self):
        return self.timeLog
        
    def getStartTime(self):
        return self.startTime
        
    def getEndTime(self):
        return self.endTime
        
    def getTimePerInt(self):
        return self.timePerInt
        
    def getRunTime(self):
        return self.runTime
        
    def getRunVals(self):
        return self.runVals
        
# --- Additional Functions
    
    def preSimSetup(self):
        self.newPop.setPop()
        self.newPop.logStart() 
        self.newPop.createInitialGraph()
        self.runVals = [(self.popSize), (self.intsPerTime * self.popSize), self.meanPosVal, self.meanAvoidVal, 
                        self.newDisease.getSickValue(), self.newDisease.getSickTime(), self.disRisk, 
                        self.newDisease.getTransRate(), self.immuneProb]
        
        timeLogFirstRow = ["Time", "PopSize", "NumSick", "NumImmune", "New Disease Transmissions", "Effective R0", "NumInteractions"]
        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)
开发者ID:drRussClay,项目名称:AB_Simulation-BIS,代码行数:70,代码来源:Simulation.py

示例2: __init__

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

    def __init__(self, simNum):
        self.simNum = simNum
        self.numTimePeriods = 50 # number of time periods that a simulation should run
        self.logInteractions = True # boolean indicating whether to log each interaction during the simulation (set to 'false' for large populations)
        self.popSize = 1000 #Size of the population
        self.minFam = 2 # minimum number of agents in each family
        self.maxFam = 6 # maximum number of agents in each family
        self.igConnectMin = 2 # minimum number of ingroup (non-family) connections for each agent
        self.igConnectMax = 5 # maximum number of ingroup (non-family) connections for each agent 
        self.xConnects = round(.1 * self.popSize) # set the number of outgroup connections as a proportion of the total population size
        self.meanPosVal = 1 # set the average health value change resulting from an interaction
        self.meanAvoidVal = -1 # set the average health value change resulting from avoiding an interaction
        self.immuneProb = 0 # set the probability that an agent has natural immunity from disease
        self.newDisease = Disease() # initialize a disease that can be spread in the poppulation
        self.newPop = Population(self.popSize, self.immuneProb, self.newDisease, self.xConnects, self.minFam, self.maxFam, self.igConnectMin, self.igConnectMax) # initialize a new population graph using the parameters set above
        self.intLog = [] # initialize a new interaction log as a list
        self.totalInts = 0 # initialize the total number of interactions to zero
        self.timeLog = [] # initialize a new log for summary statistics at each time period
        self.startTime = None # initialize the variable to hold the system time associated with the start of the simulation
        self.endTime = None # initialize the variable to hold the system time associated with the end of the simulation
        self.timePerInt = None # initialize the variable to hold the average time per interaction during the simulation
        self.runTime = None # initialize the variable to hold the total run time of the simultion
        self.runVals = None # initialize the variable to hold the log of parameters governing the simulation run
        
# --- Accessor Functions
    def getSimNum(self):
        return self.simNum
        
    def getNumTimePeriods(self):
        return self.numTimePeriods
        
    def getLogInteractions(self):
        return self.logInteractions
        
    def getPopSize(self):
        return self.getPopSize
        
    def getMinFam(self):
        return self.minFam
        
    def getMaxFam(self):
        return self.maxFam
        
    def getIGConnectMin(self):
        return self.igConnectMin
        
    def getIGConnectMax(self):
        return self.igConnectMax
              
    def getIntsPerTime(self):
        return self.intsPerTime
                
    def getMeanPosVal(self):
        return self.meanPosVal
        
    def getMeanAvoidVal(self):
        return self.meanAvoidVal
           
    def getImmuneProb(self):
        return self.immuneProb
        
    def getDisease(self):
        return self.newDisease
        
    def getPopulation(self):
        return self.newPop
        
    def getIntLog(self):
        return self.intLog
        
    def getTotalInts(self):
        return self.totalInts
        
    def getTimeLog(self):
        return self.timeLog
        
    def getStartTime(self):
        return self.startTime
        
    def getEndTime(self):
        return self.endTime
        
    def getTimePerInt(self):
        return self.timePerInt
        
    def getRunTime(self):
        return self.runTime
        
    def getRunVals(self):
        return self.runVals

#-------------------------        
# --- Class Functions
#-------------------------
    
    def preSimSetup(self):
        # Create initial Population
        self.newPop.setPop()
#.........这里部分代码省略.........
开发者ID:drRussClay,项目名称:Simulation,代码行数:103,代码来源:Simulation.py


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