Package teamwork :: Package multiagent :: Module PsychAgents :: Class PsychAgents
[hide private]
[frames] | no frames]

Class PsychAgents

source code

             object --+            
                      |            
                   dict --+        
                          |        
Multiagent.MultiagentSystem --+    
                              |    
Simulation.MultiagentSimulation --+
                                  |
                                 PsychAgents
Known Subclasses:

A PsychSim scenario

  1. Create a scenario from a list of Agent objects
  2. If the members have been created from elements of a GenericSociety, then the following applies those generic models to the member teamwork.agent.Agent objects:
  3. Access a (possibly recursively nested) member agent model
  4. Run the simulation
  5. Access the scenario state distribution
  6. Access the system dynamics
Instance Methods [hide private]
new empty dictionary

__init__(self, entities=[])
Initializes a simulation to contain the given list of agents.
source code
 
initialize(self)
Do any necessary preparation before doing whatever
source code
 
addMember(self, agent)
Adds the agent to this collection
source code
KeyedVector
getActions(self)
Returns: the current observation vector
source code
 
applyDefaults(self, progress=None, total=None, doBeliefs=True)
Applies the relevant generic models to the member agent models
source code
 
applyOrder(self, entities=None)
Applies any generic society's order specification to this scenario
source code
 
microstep(self, turns=[], hypothetical=False, explain=False, suggest=False, debug=Debugger (0))
Step forward by the action of the given entities
source code
 
individualObs(self, state, actions, observation, agent)
Probability of the specified observation
source code
Agent
getMember(self, agent)
Access the agent object stored in this scenario
source code
dict
performMsg(self, msg, sender, receivers, hearers=[], debug=Debugger (0), explain=False)
Updates the scenario in response to the specified message
source code
 
updateAll(self, action, debug=Debugger (0))
Obsolete, still here for backward compatibility
source code
 
compileDynamics(self, progress=None, total=100, profile=False)
Pre-compiles all of the dynamics trees for these agents
source code
 
compilePolicy(self, level=0, progress=None, total=100)
Pre-compiles policy trees for member agents
source code
PWLDynamics
getDynamics(self, actionDict, lock=None, debug=False)
Returns the overall dynamics function over the provided actions
source code
 
getStateDynamics(self, actionDict, errors=None)
Returns: the dynamics of the state vector in response to the given action
source code
dict
verifyTree(self, tree, validKeys=None, errors=None)
Identifies and removes any extraneous keys in the given matrices
source code
 
getActionDynamics(self, actionDict)
Returns: the dynamics of the action vector in response to the given action
source code
 
getDynamicsMatrix(self, worlds, lookup)
Generates matrix representations of probabilistic dynamics, given the space of possible worlds
source code
dict
hypotheticalAct(self, actions, beliefs=None, debug=Debugger (0))
Computes the scenario changes that would result from a given action
source code
 
__updateAgent(self, entity, actions, delta, lock, world, debug) source code
 
performAct(self, actions, debug=Debugger (0))
Updates all of the entities in response to the given actions
source code
 
applyChanges(self, delta, descend=True, rewind=False, beliefs=None)
Applies the differential changes to this set of entities
source code
KeyedVector[]
reachable(self, horizon, reachable=None, states=None)
Generates the possible real-world states reachable from the current states
source code
dict,dict
generateWorlds(self, level=0, maxSize=100, worlds=None)
Generates the space of possible n-level worlds within the current simulation
source code
 
explainEffect(self, actions, effect={}, prefix=None) source code
 
explainAction(self, actions) source code
 
explainExpectation(self, breakdown) source code
 
explainDecision(self, actor, explanation)
Extracts explanation from explanation structure
source code
 
explainMessage(self, name, explanation)
Extracts explanation from message acceptance explanation structure
source code
 
setModelChange(self, flag=-1)
Sets the model change flag value across all entities
source code
(str,str,str)[]
detectViolations(self, action, objectives=None)
Determines which objectives the given action violates
source code
Document
suggestAll(self, actor, option)
Generates alternative beliefs that might change the given action into one that satisfies all objectives
source code
dict[]
suggest(self, actor, action, objective)
Suggest alternative beliefs that might change the given action into one that satisfies the given objective
source code
 
toHTML(self) source code
 
__xml__(self) source code
 
parse(self, element, agentClass=None, societyClass=None) source code
 
__copy__(self) source code
 
__deepcopy__(self, memo) source code

Inherited from Simulation.MultiagentSimulation: actionCount, activeMembers, actorCount, applyTurn, createTurnDynamics, deleteState, generateActions, generateOrder, getSequence, getState, getStateKeys, initializeOrder, next, updateTurn

Inherited from Multiagent.MultiagentSystem: __str__, members, save

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __setitem__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__

Class Variables [hide private]
float observationDecay = 0.5
the rate at which an observation flag decays on each subsequent epoch (1 means no decay, 0 means instant amnesia)
  __VERIFY__ = True
boolean threaded = False
if True, then execution will be multithreaded

Inherited from Simulation.MultiagentSimulation: threshold, turnFeature

Instance Variables [hide private]

Inherited from Simulation.MultiagentSimulation: order, time

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, entities=[])
(Constructor)

source code 

Initializes a simulation to contain the given list of agents. If you would like to create your own turn state and dynamics, override the methods generateOrder and createTurnDynamics.

Parameters:
  • entities - list or dictionary of Agent instances
Returns:
new empty dictionary

Overrides: object.__init__

initialize(self)

source code 

Do any necessary preparation before doing whatever

Overrides: Multiagent.MultiagentSystem.initialize
(inherited documentation)

addMember(self, agent)

source code 

Adds the agent to this collection

Parameters:
  • agent (Agent) - the agent to add
Overrides: Multiagent.MultiagentSystem.addMember

Warning: will clobber any pre-existing agent with the same name

getActions(self)

source code 
Returns: KeyedVector
the current observation vector

applyDefaults(self, progress=None, total=None, doBeliefs=True)

source code 

Applies the relevant generic models to the member agent models

Parameters:
  • progress (Queue) - optional Queue argument is used to give progress updates, in the form of (label,pct), where:
    • label: a string label to display for the current task
    • pct: an integer percentage (1-100) representing the amount of progress made since the last call
  • total (float) - number of total actions to be progressed through
  • doBeliefs (bool) - if True, the create recursive beliefs (default is True

microstep(self, turns=[], hypothetical=False, explain=False, suggest=False, debug=Debugger (0))

source code 

Step forward by the action of the given entities

Parameters:
  • turns (dict[]) - the agents to act next (defaults to result of next), each entry in the list should be a dictionary:
    • name: the name of the agent to act
    • choices: the list of possible options this agent can consider in this turn (defaults to the list of all possible actions if omitted, or if the list is empty)
  • hypothetical (bool) - if True, then this is only a hypothetical microstep; otherwise, it is real
  • explain (bool) - if True, then add an explanation to the result
  • suggest (bool) - if True, then suggest possible belief changes to ensure that the behavior in this step meets whatever objectives have been specifieid (default is False)
Returns:
a dictionary of results:
  • decision: the dictionary of actions performed in this turn
  • delta: the changes to the state (suitable for passing in to applyChanges)
  • explanation: an XML document explaining what happened in this step and why

Note: if explain is False, then suggest is treated as False

individualObs(self, state, actions, observation, agent)

source code 

Probability of the specified observation

Warning: to be overridden

getMember(self, agent)

source code 

Access the agent object stored in this scenario

Parameters:
  • agent (string or list of strings) - the label for the entity to be returned, either:
    • if a string, the entity object of that name
    • if a list of strings, then the list is treated as a recursive path representing a branch of the belief hierarchy, and the end node is returned
Returns: Agent
the member agent contained in this team that corresponds to the specified agent object or string name
Overrides: Multiagent.MultiagentSystem.getMember

performMsg(self, msg, sender, receivers, hearers=[], debug=Debugger (0), explain=False)

source code 

Updates the scenario in response to the specified message

Parameters:
  • msg (Message) - the message to be sent
  • sender (str) - name of the agent sending this message
  • receivers (str[]) - list of agent names who are the intended receivers
  • hearers (str[]) - list of agent names who are unintended hearers
  • explain (boolean) - if True, then add an explanation to the result
Returns: dict
the overall effect of this message

Note: hearers is optional, but should not contain any of the receivers

compileDynamics(self, progress=None, total=100, profile=False)

source code 

Pre-compiles all of the dynamics trees for these agents

Parameters:
  • progress (lambda) - optional progress argument is invoked to give progress updates, in the form of lambda label,pct: ..., where:
    • label: a string label to display for the current task
    • pct: an integer percentage (1-100) representing the amount of progress made since the last call
  • total (int) - the total number of actions to be compiled
  • profile (boolean) - if True, a profiler is run and statistics printed out (default is False

Warning: pre-compiles only those trees missing from cache.

Note: Applies this method to recursive beliefs of member agents as well

compilePolicy(self, level=0, progress=None, total=100)

source code 

Pre-compiles policy trees for member agents

Parameters:
  • level (int) - The belief depth at which all agents will have their policies compiled, where 0 is the belief depth of the real agent. If the value of this flag is n, then all agents at belief depth≥n will have their policies compiled, while no agents at belief depth<n will. If None, then no agents will have policies compiled.

Warning: pre-compiles only those trees missing from cache.

Note: Applies this method to recursive beliefs of member agents as well

getDynamics(self, actionDict, lock=None, debug=False)

source code 

Returns the overall dynamics function over the provided actions

Parameters:
  • lock - optional thread lock
Returns: PWLDynamics

getStateDynamics(self, actionDict, errors=None)

source code 
Parameters:
  • actionDict (dict:str->Action[]) - the actions performed, indexed by actor name
  • errors (dict) - a dictionary to hold any dynamics bugs that are corrected (by default, the bugs are corrected but not returned)
Returns:
the dynamics of the state vector in response to the given action

verifyTree(self, tree, validKeys=None, errors=None)

source code 

Identifies and removes any extraneous keys in the given matrices

Parameters:
  • tree (KeyedTree[]) - the tree to check
  • errors (dict:StateKey[]→True) - the errors found so far (defaults to empty)
Returns: dict
the extraneous keys found (StateKey[]→True)

getActionDynamics(self, actionDict)

source code 
Parameters:
  • actionDict (dict:str->Action[]) - the actions performed, indexed by actor name
Returns:
the dynamics of the action vector in response to the given action

hypotheticalAct(self, actions, beliefs=None, debug=Debugger (0))

source code 

Computes the scenario changes that would result from a given action

Parameters:
  • actions (dict:str->Action[]) - dictionary of actions, where each entry is a list of Action instances, indexed by the name of the actor
Returns: dict
the changes that would result from actions

performAct(self, actions, debug=Debugger (0))

source code 

Updates all of the entities in response to the given actions

Parameters:
  • actions - a dictionary of actions, indexed by actor name
Returns:
a dictionary of the changes, returned by hypotheticalAct

reachable(self, horizon, reachable=None, states=None)

source code 

Generates the possible real-world states reachable from the current states

Parameters:
  • horizon (int) - the number of time steps to project into the future
Returns: KeyedVector[]

Note: Observations are not tracked, as we assume that they do not affect reachability

generateWorlds(self, level=0, maxSize=100, worlds=None)

source code 

Generates the space of possible n-level worlds within the current simulation

Parameters:
  • level (int) - n
  • maxSize (int) - the upper limit on the size of the generated space (Default is 100)
Returns: dict,dict
dictionary of worlds, indexed by WorldKey, and a reverse lookup dictionary as well (i.e., WorldKeyKeyedVector,KeyedVectorWorldKey

setModelChange(self, flag=-1)

source code 

Sets the model change flag value across all entities

Parameters:
  • flag (int) - if flag argument is positive, activates model changes in the belief updates of these entities; if 0, deactivates them; if negative (default), toggles the activation state

detectViolations(self, action, objectives=None)

source code 

Determines which objectives the given action violates

Parameters:
  • objectives ((str,str,str)[]) - the objectives to test (default is all)
  • action (Action)
Returns: (str,str,str)[]

suggestAll(self, actor, option)

source code 

Generates alternative beliefs that might change the given action into one that satisfies all objectives

Parameters:
  • option (Action[])
  • actor (str)
Returns: Document

suggest(self, actor, action, objective)

source code 

Suggest alternative beliefs that might change the given action into one that satisfies the given objective

Parameters:
  • action (Action[])
  • objective ((str,str,str))
  • actor (str)
Returns: dict[]

__xml__(self)

source code 
Overrides: Multiagent.MultiagentSystem.__xml__

parse(self, element, agentClass=None, societyClass=None)

source code 
Parameters:
  • agentClass (class) - the Python class for the individual entity members
  • societyClass (class) - the optional Python class for any generic society associated with this scenario
Overrides: Multiagent.MultiagentSystem.parse

__copy__(self)

source code 
Overrides: Simulation.MultiagentSimulation.__copy__

__deepcopy__(self, memo)

source code 
Overrides: Simulation.MultiagentSimulation.__deepcopy__