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


Python Agent.decide方法代码示例

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


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

示例1: NormalARD

# 需要导入模块: from Agent import Agent [as 别名]
# 或者: from Agent.Agent import decide [as 别名]
lik = np.log(np.array([0.00001]))
hyp = np.log(np.array([1, 1, 10]))
cov = NormalARD()
gp = GaussianProcess(lik, hyp, cov)
gp2 = GaussianProcess(lik, hyp, cov)

sig =np.ones((3,)) * 0.001
sig2 = np.ones((3,)) * 0.1
start_z = np.array([[0., 0., 0.]])
agent = Agent(gp, reward, sig, start_z)
agent2 = Agent(gp2, reward, sig2, start_z)
fig = plt.figure(figsize=(20,7), dpi=300)
zlim = (-10, 10, -10, 10)
for i in xrange(0, 1000):
    agent.observe()
    agent.decide()
    agent.act()
    agent2.observe()
    agent2.decide()
    agent2.act()

    t = agent.gp.Z[-1].flatten()[-1]
    a = [0] * 4
    a[0] = agent.gp.Z[-1].flatten()[0]
    a[1] = agent.gp.Z[-1].flatten()[1]
    a[2] = agent.gp.Z[-1].flatten()[0]
    a[3] = agent.gp.Z[-1].flatten()[1]
    extent = np.max(np.abs(a))
    lim = extent + 3 if extent > 10 else 10
    zlim = (-lim, lim, -lim, lim)
    fig.clf()
开发者ID:c0g,项目名称:PyAgent,代码行数:33,代码来源:wander.py

示例2: execute

# 需要导入模块: from Agent import Agent [as 别名]
# 或者: from Agent.Agent import decide [as 别名]
 def execute(self):        
     ##
     ## Initialize agents
     ##
     pDisease = {Constant.BETA: 1 - math.exp(-self.disease[Constant.BETA]),
                 Constant.RHO: self.disease[Constant.RHO],
                 Constant.GAMMA: 1 - math.exp(-self.disease[Constant.GAMMA])}
     
     self.decision = 1 - math.exp(-self.decision)
             
     N = 0
     agents = []
     infected = []
     for state in self.nAgents:            
         for x in range(self.nAgents[state]):
             agent = Agent(N, state, pDisease, self.fear, self.timeHorizon, self.payoffs)
             agents.append(agent)
             
             if (state == State.I):
                 infected.append(agent)
             
             N += 1
     ##
     ## Output variables
     ##
     num = []
     num.append([0,
                 self.nAgents[State.S],
                 self.nAgents[State.P],
                 0,
                 self.nAgents[State.I],
                 0,
                 0,
                 self.nAgents[State.R],
                 0,
                 0,
                 self.nAgents[State.S] * self.payoffs[State.S],
                 self.nAgents[State.P] * self.payoffs[State.P],
                 self.nAgents[State.I] * self.payoffs[State.I],
                 self.nAgents[State.R] * self.payoffs[State.R]])
     
     ##
     ## Run the simulation
     ##
     t = 1
     i = self.nAgents[State.I] / float(N)
     
     while ((t < self.timeSteps) and (i > 0)):
         numagents = [0, 0, 0, 0]
         
         ##
         ## Interaction
         ##
         shuffle(agents)
         
         n = N
         infected = []
         while(n > 1):
             a1 = agents[n - 1]
             a2 = agents[n - 2]
             
             a1State = a1.getState()
             a2State = a2.getState()
             
             a1S = a1State
             a2S = a2State
             
             if (a1State == State.I):
                 infected.append(a1)
                 a2S = a2.interact(a1State)
                 
             if (a2State == State.I):
                 infected.append(a2)
                 a1S = a1.interact(a2State)
             
             numagents[a1S] += 1
             numagents[a2S] += 1
             
             n = n - 2
         
         ##
         ## Decision
         ##
         for agent in agents:
             if (uniform(0.0, 1.0) < self.decision):
                 
                 state = agent.getState()
                 numagents[state] -= 1
                 
                 state = agent.decide(i)
                 numagents[state] += 1
         
         ##
         ## Recover
         ##
         for agent in infected:
             if (agent.recover() == State.R):
                 numagents[State.I] -= 1
                 numagents[State.R] += 1
         
#.........这里部分代码省略.........
开发者ID:bertybaums,项目名称:SPIR,代码行数:103,代码来源:MicroMethod.py


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