def configure(sim): """use this function to configure the given simulation""" # customize settings sim.settings.deltaTime = timedelta(days=1) sim.settings.simStartTime = datetime(2011, 1, 1, 12, 0, 0, 0) sim.settings.t0 = 0 #startTime sim.settings.tf = 180 #endTime # load agents personalities for i, ii, and iii agent1 = agent(sim.environment) agent1.state.setPersonality(agent_i.personality()) agent2 = agent(sim.environment) agent2.state.setPersonality(agent_ii.personality()) agent3 = agent(sim.environment) agent3.state.setPersonality(agent_iii.personality()) #add disturbances agent3.state.eta_PA.setFunction(getEta, agent3.inputs.xi_PA, agent3.state.personality, agent3.state.zeta_PA) agent3.state.eta_EB.setFunction(getEta, agent3.inputs.xi_EB, agent3.state.personality, agent3.state.zeta_EB) # customize the CSEL input functions (exogeneous flow vars) def eatingAttitude(t): beforeChange = 7 afterChange = 10 changeT = 10 allOthers = 1 return stepOne(t, allOthers, 'behavioralBelief', changeT, beforeChange, afterChange) agent1.inputs.attitudeChange_EB.setFunction( eatingAttitude) #overwrite the default function agent2.inputs.attitudeChange_EB.setFunction( eatingAttitude) #overwrite the default function agent3.inputs.attitudeChange_EB.setFunction( eatingAttitude) #overwrite the default function def exerciseAttitude(t): # stepOne(data,t,value,steppedName,stepTime,beforeStep,afterStep): beforeChange = 1 afterChange = 3 changeT = 30 allOthers = 1 return stepOne(t, allOthers, 'behavioralBelief', changeT, beforeChange, afterChange) agent1.inputs.attitudeChange_PA.setFunction( exerciseAttitude) #overwrite the default function agent2.inputs.attitudeChange_PA.setFunction( exerciseAttitude) #overwrite the default function agent3.inputs.attitudeChange_PA.setFunction( exerciseAttitude) #overwrite the default function
def configure(sim): sim.settings = settings() sim.environment = environment() agent(sim.environment)
settings.simStartTime = datetime(2011, 1, 1, 12, 0, 0, 0) print '* simulation start time (sim-time): ' + str(settings.simStartTime) print '* size of time step, deltaTime: ' + str(settings.deltaTime) t0 = 0 #startTime tf = 180 #endTime # === === === === === === AGENT SETUP === === === === === === from behaviorSim.environment.environment import environment envmt = environment() # load default environment # load agents personalities for i, ii, and iii from behaviorSim.PECSagent.agent import agent from behaviorSim.PECSagent.state.CSEL import agent_i, agent_ii, agent_iii agent1 = agent(envmt) agent1.state.setPersonality(agent_i.personality()) agent2 = agent(envmt) agent2.state.setPersonality(agent_ii.personality()) agent3 = agent(envmt) agent3.state.setPersonality(agent_iii.personality()) #add disturbances from behaviorSim.PECSagent.state.CSEL.model_ddeint_firstOrder_withDisturbances import getEta # print 'args='+str(agent3.state.eta_PA.args) #def getEta(data,t,xi_PA,agent,zeta_PA): agent3.state.eta_PA.setFunction(getEta,agent3.inputs.xi_PA,agent3.state.personality,agent3.state.zeta_PA) agent3.state.eta_EB.setFunction(getEta,agent3.inputs.xi_EB,agent3.state.personality,agent3.state.zeta_EB) # customize the CSEL input functions (exogeneous flow vars)
t = 5 #time of interest in simulation timesteps (set in settings) #setup log file for this script import logging from behaviorSim.__util.setupLog import setupLog setupLog() # === === === === === === AGENT SETUP === === === === === === from behaviorSim.environment.environment import environment envmt = environment() #load default environment from behaviorSim.PECSagent.agent import agent myAgent = agent(envmt) #load default agent #TODO: customize the agent #TODO: defaultAgent.tag = 'my very first agent' # you can not reference the agent using 'myAgent' or 'envmt.agent[0]' # add agent to environment print ' === === === === === === SETTINGS === === === === === ===' # load settings of the simulation (just FYI here) from behaviorSim.PECSagent.settings import settings print '* simulation start time (sim-time): ' + str(settings.simStartTime) print '* size of time step, deltaTime: ' + str(settings.deltaTime) print ' === === === === === === DATA === === === === === ===' print envmt.agents[0].inputs(0) print envmt.agents[0].state(0) print envmt.agents[0].motive(0) print envmt.agents[0].behavior(0)
settings.simStartTime = datetime(2011, 1, 1, 12, 0, 0, 0) print '* simulation start time (sim-time): ' + str(settings.simStartTime) print '* size of time step, deltaTime: ' + str(settings.deltaTime) t0 = 0 #startTime tf = 180 #endTime # === === === === === === AGENT SETUP === === === === === === from behaviorSim.environment.environment import environment envmt = environment() # load default environment # load agents personalities for i, ii, and iii from behaviorSim.PECSagent.agent import agent from behaviorSim.PECSagent.state.CSEL import agent_i, agent_ii, agent_iii agent1 = agent(envmt) agent1.state.setPersonality(agent_i.personality()) agent2 = agent(envmt) agent2.state.setPersonality(agent_ii.personality()) agent3 = agent(envmt) agent3.state.setPersonality(agent_iii.personality()) #add disturbances from behaviorSim.PECSagent.state.CSEL.model_ddeint_firstOrder_withDisturbances import getEta # print 'args='+str(agent3.state.eta_PA.args) #def getEta(data,t,xi_PA,agent,zeta_PA): agent3.state.eta_PA.setFunction(getEta, agent3.inputs.xi_PA, agent3.state.personality, agent3.state.zeta_PA) agent3.state.eta_EB.setFunction(getEta, agent3.inputs.xi_EB, agent3.state.personality, agent3.state.zeta_EB)
from behaviorSim.environment.environment import environment envmt = environment() #load default environment from behaviorSim.PECSagent.agent import agent agent1 = agent(envmt) #load default agent t = 3 # === how the raw data is handled (don't do this) === # attempted direct access shows data in memory (don't do this) print ' initTime: ' + str(agent1.inputs.initTime.data) # note that it is empty, something likke _inputs__initTime[t] here would cause out-of-bounds exception # function call ensures that value is present and up-to-date (this is what you should be using) print 'initTime(t): ' + str(agent1.inputs.initTime(t)) # and updates the raw data (as shown) (do not do this) print ' initTime: ' + str(agent1.inputs.initTime.data)
def setupAgent(self, sim): print 'setting up default agent...' sim.environment.addAgent(agent(sim.environment)) #add a default agent print 'done'
def configure(sim): # set up the question(s) #TODO: question should include prospect of outcomes, ... MORE class questionIterator(object): ''' This class returns the current question being posed. ''' def __init__(self): self.currentQuestionN = 0 self.currentQuestion = None self.questions = [[2500,.33,2400,.66,0,.01], [2500,.33,0 ,.67], [4000,.8 ,3000], ] def __call__(self,t,agent): # update question if agent has competed last question if agent.behavior.choice(t) != None: self.currentQuestionN += 1 self.currentQuestion = self.getQuestion() return self.currentQuestion def getQuestion(self): n = self.currentQuestionN if n<1: raise ValueError('question # cannot be negative') elif n == 1: self.currentQuestion = [] elif n == 2: self.currentQuestion = [] else: raise ValueError('question #'+str(n)+' not found') return self.currentQuestion currentQuestionProspect = API.getConstruct('currentQuestionProspect' ,questionIterator) # this should be None when there is no prospect question posed, # if there is a question it is a list API.addFeature(environment,time,) #sim.environment.??? API.addEvent(environment,time, gamblePrompt) # create rational agent rationalAgent = agent(sim.environment) class event: if time == timeTrigger: triggerEvent(environment) prospect = API.getConstruct('prospect' ,getProspectFromEnvironment ,environment.currentQuestionProspect) API.addConstruct(rationalAgent.context,prospect) def expectation(prospect): ''' returns expectation value for given set of probabilities t = time prospect = list of outcome and probability pairs (x_1,p_1,x_2,p_2...x_n,p_n) ''' sum = 0 for i in range(int(len(prospect)/2)): sum += prospect[i*2]*prospect[i*2+1] return sum #TODO: def utilityOfAssets(assetPosition) #TODO: def assetIntegration(prospect,assetPosition): #TODO: def riskAversionAssetUtility(assetPosition): # ''' this is a concave function of assetPosition ''' expectation = API.getConstruct('expectation' ,calculateExpectationValue ,rationalAgent.context.prospect) API.addConstruct(rationalAgent.state,expectationValue) # create a classically risk-averted agent riskAvertedAgent = copy.deepcopy(rationalAgent) # create a more realistic human agent by extending the rational agent prospectTheoryAgent = copy.deepcopy(rationalAgent)
def getDefaultAgent(envmt): from behaviorSim.PECSagent.agent import agent return agent(envmt)
t = 5 #time of interest in simulation timesteps (set in settings) #setup log file for this script import logging from behaviorSim.__util.setupLog import setupLog setupLog() # === === === === === === AGENT SETUP === === === === === === from behaviorSim.environment.environment import environment envmt = environment() #load default environment from behaviorSim.PECSagent.agent import agent myAgent = agent(envmt) #load default agent #TODO: customize the agent #TODO: defaultAgent.tag = 'my very first agent' # you can not reference the agent using 'myAgent' or 'envmt.agent[0]' # add agent to environment print ' === === === === === === SETTINGS === === === === === ===' # load settings of the simulation (just FYI here) from behaviorSim.PECSagent.settings import settings print '* simulation start time (sim-time): ' + str(settings.simStartTime) print '* size of time step, deltaTime: ' + str(settings.deltaTime) print ' === === === === === === DATA === === === === === ===' print envmt.agents[0].inputs(0)
def configure(sim): # set up the question(s) #TODO: question should include prospect of outcomes, ... MORE class questionIterator(object): ''' This class returns the current question being posed. ''' def __init__(self): self.currentQuestionN = 0 self.currentQuestion = None self.questions = [ [2500, .33, 2400, .66, 0, .01], [2500, .33, 0, .67], [4000, .8, 3000], ] def __call__(self, t, agent): # update question if agent has competed last question if agent.behavior.choice(t) != None: self.currentQuestionN += 1 self.currentQuestion = self.getQuestion() return self.currentQuestion def getQuestion(self): n = self.currentQuestionN if n < 1: raise ValueError('question # cannot be negative') elif n == 1: self.currentQuestion = [] elif n == 2: self.currentQuestion = [] else: raise ValueError('question #' + str(n) + ' not found') return self.currentQuestion currentQuestionProspect = API.getConstruct('currentQuestionProspect', questionIterator) # this should be None when there is no prospect question posed, # if there is a question it is a list API.addFeature( environment, time, ) #sim.environment.??? API.addEvent(environment, time, gamblePrompt) # create rational agent rationalAgent = agent(sim.environment) class event: if time == timeTrigger: triggerEvent(environment) prospect = API.getConstruct('prospect', getProspectFromEnvironment, environment.currentQuestionProspect) API.addConstruct(rationalAgent.context, prospect) def expectation(prospect): ''' returns expectation value for given set of probabilities t = time prospect = list of outcome and probability pairs (x_1,p_1,x_2,p_2...x_n,p_n) ''' sum = 0 for i in range(int(len(prospect) / 2)): sum += prospect[i * 2] * prospect[i * 2 + 1] return sum #TODO: def utilityOfAssets(assetPosition) #TODO: def assetIntegration(prospect,assetPosition): #TODO: def riskAversionAssetUtility(assetPosition): # ''' this is a concave function of assetPosition ''' expectation = API.getConstruct('expectation', calculateExpectationValue, rationalAgent.context.prospect) API.addConstruct(rationalAgent.state, expectationValue) # create a classically risk-averted agent riskAvertedAgent = copy.deepcopy(rationalAgent) # create a more realistic human agent by extending the rational agent prospectTheoryAgent = copy.deepcopy(rationalAgent)
def setupAgent(self,sim): print 'setting up default agent...' sim.environment.addAgent(agent(sim.environment)) #add a default agent print 'done'
import pylab # === === === === === === AGENT SETUP === === === === === === from behaviorSim.environment.environment import environment envmt = environment() #load default environment from behaviorSim.PECSagent.agent import agent agent1 = agent(envmt) #load default agent # === === === === === === PLOTS === === === === === === from behaviorSim.PECSplotter.plot import plotAll, plotInputs, plotState #load the plotter print 'plot using plotAll? (y/n)' choice = raw_input() while choice != 'n' and choice != 'y': print choice + '? please enter y or n.' choice = raw_input() if choice == 'y': plotAll(agent1,0,10) # and show the plots: pylab.show() print 'plot using individual plotters? (y/n)' choice = raw_input() while choice != 'n' and choice != 'y': print choice + '? please enter y or n.' choice = raw_input() if choice == 'y': #using the built-in plotters: plotInputs(agent1,0,10) #plot inputs t={0->10} plotState(agent1,0,10)