def reset(self, p): """ Reset the agent to it's initial birth conditions. """ self.temp = self.startTemp self.speed = kai.calcAgentSpeed(self.kai.KAI, p) self.r = np.random.uniform(-1, 1, size=p.nDims) self.memory = [Solution(self.r, self.score, type(self))] self.nmoves = 0 self.score = np.inf
def __init__(self, agentConstructor, p, kaiPopulation): """ Create a Team of given Agent class according to model parameters. Parameters ---------- agentConstructor : costructor Class for desired agents (eg, Steinway) p : Params object, contains current model Parameters kaiPopulation: list of KAIScore, virtual population to draw from Returns ------- self : Team object """ #initialize the team with the desired agents self.agents = [] aiScores = np.zeros(p.nAgents) #curated team composition: if (p.aiScore is not None) and (p.aiRange is not None): minScore = np.max([40, p.aiScore - p.aiRange / 2.0]) maxScore = np.min([150, p.aiScore + p.aiRange / 2.0]) aiScores = np.linspace(minScore, maxScore, p.nAgents) np.random.shuffle( aiScores) #randomly assign these to agents, not in order... for i in range(p.nAgents): a = agentConstructor(p) #creates an agent with random kai score if p.startPositions is not None: a.startAt(p.startPositions[i]) #if necessary, give the agent a specific style (kai score): if (p.aiScore is not None) and (p.aiRange is not None): aiScore = aiScores[i] a.kai = kai.findAiScore(aiScore, kaiPopulation) a.speed = kai.calcAgentSpeed(a.kai.KAI, p) a.temp = kai.calcAgentTemp(a.kai.E, p) a.startSpeed = a.speed a.startTemp = a.temp #by default, all dimensions are owned by every agent a.myDims = np.ones(p.nDims) self.agents.append(a) self.nAgents = p.nAgents aiScores = [a.kai.KAI for a in self.agents] self.dAI = np.max(aiScores) - np.min(aiScores) #record the team's process and behaviors: self.nMeetings = 0 self.shareHistory = [] self.nTeamMeetings = 0 self.subTeamMeetings = 0 self.meetingDistances = [] self.scoreHistory = [] #if there are subteams owning certain dimensions, #each subteams dimensions are listed in a matrix self.specializations = p.teamDims
def reset(self, p): """ Reset the agent to it's initial birth conditions. """ self.temp = self.startTemp self.speed = kai.calcAgentSpeed(self.kai.KAI, p) self.memory = [] self.beam = Beam() self.r = self.beam.normVector() self.nmoves = 0 self.score = np.inf
def reset(self,p): """ Reset the agent to it's initial birth conditions. """ self.temp = self.startTemp self.speed = kai.calcAgentSpeed(self.kai.KAI,p) self.memory = [] self.car = carObjective.startCarParams() self.r = carObjective.normalizedCarVector(self.car) self.nmoves = 0 self.score = np.inf
def __init__(self, p): """ Initialize the agent. """ self.score = np.inf self.r = np.random.uniform(-1, 1, size=p.nDims) self.nmoves = 0 self.kai = kai.KAIScore() self.speed = kai.calcAgentSpeed(self.kai.KAI, p) self.temp = kai.calcAgentTemp(self.kai.E, p) self.memory = [Solution(self.r, self.score, type(self))] self.team = -1 self.decay = kai.calculateAgentDecay(self, 100) self.startTemp = h.cp(self.temp) self.startSpeed = h.cp(self.speed)
def createCustomTeam(p, agentConstructor = CarDesignerWeighted, subTeamToVary = 0, subTeamKAI = 95): """ Create a team of agents before running it through the simulation. Design the team with a specific composition of KAI scores, and subdivision of a problem into specialized subteams Parameters ---------- p : Params object, contains current model Parameters including p.nAgents, p.nTeams, p.nDims, p.AVG_SPEED, p.AVG_TEMP AgentConstructor : constructor class (default = Steinway) Returns ------- myTeam: Team object with desired characteristics, ready to run in the model """ p.aiScore = 95 p.aiRange = 0 myTeam = createTeam(p,agentConstructor) #now, we need to make a specific sub-team have a different ai composition for i, a in enumerate(myTeam.agents): if a.team == subTeamToVary: a.kai = kai.findAiScore(subTeamKAI) a.speed = kai.calcAgentSpeed(a.kai.KAI,p) a.temp = kai.calcAgentTemp(a.kai.E,p) a.decay = kai.calculateAgentDecay(a,p.steps) for a in myTeam.agents: a.startSpeed = h.cp(a.speed) a.startTemp = h.cp(a.temp) return myTeam
def createTeam(p,agentConstructor = Steinway): """ Create a team of agents before running it through the simulation. Design the team with a specific composition of KAI scores, and subdivision of a problem into specialized subteams Parameters ---------- p : Params object, contains current model Parameters including p.nAgents, p.nTeams, p.nDims, p.AVG_SPEED, p.AVG_TEMP AgentConstructor : constructor class (default = Steinway) Returns ------- myTeam: Team object with desired characteristics, ready to run in the model """ np.random.seed() # p.agentTeams = specializedTeams(p.nAgents,p.nTeams) # p.teamDims = teamDimensions(p.nDims,p.nTeams) # print(teamDims) myTeam = Team(agentConstructor,p,kaiPopulation) for i in range(len(myTeam.agents)): a = myTeam.agents[i] aTeam = p.agentTeams[i] a.team = aTeam a.myDims = p.teamDims[aTeam] a.decay = kai.calculateAgentDecay(a,p.steps) #adding an option to specify the exact list of KAI scores for a team (Sam 2020/02/11) #to use this, add a list of KAI scores as an attribute called "kaiList" to the Parameters object p #for example: p.kaiList = [70,80,80,101,84] #the list must have the same number of elements as there are agents on the team #to explicitly NOT use this option, set p.kaiList = None (which is the default value) if p.kaiList is not None: if len(p.kaiList) != len(myTeam.agents): raise ValueError(f'The length of Parameters.kaiList ({len(p.kaiList)}) does not match the number of agents on the team ({len(myTeam.agents)}).') for i,a in enumerate(myTeam.agents): a.kai = kai.findAiScore(p.kaiList[i]) a.speed = kai.calcAgentSpeed(a.kai.KAI,p) a.temp = kai.calcAgentTemp(a.kai.E,p) a.decay = kai.calculateAgentDecay(a,p.steps) elif p.curatedTeams and p.aiRange is not None and p.aiScore is not None: for team in range(len(p.teamDims)): teamAgents=[a for a in myTeam.agents if a.team == team] if len(teamAgents)<2: a = teamAgents[0] a.kai = kai.findAiScore(p.aiScore,kaiPopulation) a.speed = kai.calcAgentSpeed(a.kai.KAI,p) a.temp = kai.calcAgentTemp(a.kai.E,p) #should a.decay be recalculated here? I think it should... (Sam 2020/02/11) else: for i in range(len(teamAgents)): myKai = p.aiScore - p.aiRange/2.0 + p.aiRange*(float(i)/(len(teamAgents)-1)) a = teamAgents[i] a.kai = kai.findAiScore(myKai,kaiPopulation) a.speed = kai.calcAgentSpeed(a.kai.KAI,p) a.temp = kai.calcAgentTemp(a.kai.E,p) #should a.decay be recalculated here? I think it should... (Sam 2020/02/11) for a in myTeam.agents: a.startSpeed = h.cp(a.speed) a.startTemp = h.cp(a.temp) return myTeam