Package teamwork :: Package agent :: Module RecursiveAgent :: Class RecursiveAgent
[hide private]
[frames] | no frames]

Class RecursiveAgent

source code

Agent.Agent --+
              |
             RecursiveAgent
Known Subclasses:

Base class for an agent that keeps recursive models of the other agents in its world.

Nested Classes [hide private]

Inherited from Agent.Agent: actionClass

Instance Methods [hide private]
 
__init__(self, name='') source code
 
setName(self, name)
Sets the name of this agent
source code
Distribution
getState(self, feature)
Returns the current Distribution over the specified feature
source code
 
setState(self, feature, value)
Sets this entity's state value for the specified feature
source code
Distribution
getObservation(self, name)
Returns the current Distribution over the specified observation flag
source code
 
setObservation(self, name, value)
Sets this entity's observation flag for the observation type
source code
str[]
getStateFeatures(self)
Returns: names of the valid state features
source code
RecursiveAgent
getEntity(self, name)
Returns: the agent representing the beliefs about the given entity
source code
 
__getitem__(self, index)
Allows indexing into entity beliefs (i.e., entity['Bill'])
source code
boolean
hasBelief(self, entity)
Returns: True iff I have a belief about the named entity
source code
str[]
getEntities(self)
Returns: the names of entities that I have beliefs about
source code
Agent[]
getEntityBeliefs(self)
Returns: the subjective entity views that I have
source code
StateKey[]
getBeliefKeys(self)
Returns: the state features across all beliefs that this agent has
source code
 
getBelief(self, entity, feature)
Shortcut for self.getEntity(entity).getState(feature)
source code
 
getNestedBelief(self, keys)
Accesses a nested belief by following the branches specified by keys (a list of strings).
source code
 
getSelfBelief(self, feature)
Shortcut for self.getEntity(self.name).getState(feature)
source code
 
setBelief(self, name, feature, value)
Shortcut for self.getEntity(entity).{setState}(feature,value)
source code
 
setSelfBelief(self, feature, value)
Shortcut for self.setBelief(self,feature,value)
source code
 
setEntity(self, entity)
Sets my belief about the given entity to be the provided entity object.
source code
 
setRecursiveBelief(self, name, feature, value)
Helper method for setting the beliefs of a feature
source code
dict
getAllBeliefs(self)
Packages up all of this agent's beliefs into a handy dictionary
source code
(Action[],Element)
applyPolicy(self, state=None, actions=[], history=None, debug=None, explain=False)
Generates a decision chosen according to the agent's current policy
source code
 
invalidateCache(self)
Removes any cached policy value, as well as any cached policy values of my parents
source code
 
initialStateEstimator(self)
Initializes beliefs
source code
 
stateEstimator(self, beliefs, actions, epoch=-1, debug=None)
Trying to unify preComStateEstimator and postComStateEstimator
source code
dict
preComStateEstimator(self, beliefs, actions, epoch=-1, debug=None)
Computes the hypothetical changes to the given beliefs in response to the given actions
source code
KeyedMatrix
incorporateMessage(self, msg, log=None)
Update an entity's beliefs in response to set of messages
source code
KeyedMatrix
__incorporateMessage(self, factor)
Update an entity's beliefs in response to a received message
source code
list
getObservations(self)
Returns: the sequence of events that this entity has witnessed
source code
 
saveObservations(self, obs)
Adds the given observation to the history
source code
a tuple (boolean,int)
findObservation(self, action, depth=0)
Returns true iff the agent has observed the given action
source code
 
resetHistory(self, beliefs=None)
Resets the observation history of the specified beliefs (defaults to this entity's beliefs if none provided)
source code
dict
observe(self, actionDict={})
Returns: observations this entity would make of the given actions, in the same format as the provided action dictionary
source code
teamwork.math.Keys.ActionKey[]
getActionKeys(self)
Returns: the minimal set of observations relevant to this agent
source code
 
multistep(self, horizon=1, start={}, state=None, debug=None)
Steps this entity the specified number of steps into the future (where a step is one entity performing its policy-specified action)
source code
 
updateStateDict(self, original, delta) source code
 
step(self, actDict, state=None, debug=None)
Modifies the current entity in response to the policy-driven actions selected by the provided dictionary of entities.
source code
PWLDynamics
getDynamics(self, act, feature)
Returns: this entity's dynamics model for the given action
source code
 
applyChanges(self, beliefs, delta, descend=1, rewind=0)
Takes changes and modifies the given beliefs accordingly
source code
 
freeze(self)
Takes the current state of beliefs and marks it as the initial, beginning-of-the-world state of beliefs.
source code
str
ancestry(self)
Returns: a string representation of this entity's position in the recursive belief tree.
source code
int
beliefDepth(self)
Returns: the recursive depth of the current entity (0 is the depth of a root entity)
source code
 
__copy__(self) source code
 
__deepcopy__(self, memo) source code
 
__str__(self)
Returns a string representation of this entity
source code
 
toHTML(self) source code
 
__ne__(self, entity) source code
boolean
__eq__(self, entity)
Equality test between agents
source code
 
__xml__(self) source code
 
parse(self, element)
Extracts this agent's recursive belief structure from the given XML Element
source code

Inherited from Agent.Agent: __cmp__, generateAllObservations, generateHistories, legalActions, legalMessages, observable, postComStateEstimator

Instance Variables [hide private]
dict dynamics
the dynamics by which this agent's state evolves
RecursiveAgent parent
the agent whose subjective view this agent represents (None, if this is an objective view)
  relationships
inter-agent relationships from this agent.
Distribution state
the probability distribution over the state of this agent's world

Inherited from Agent.Agent: actions, name, omega

Method Details [hide private]

__init__(self, name='')
(Constructor)

source code 
Parameters:
  • name (string) - label for this instance
Overrides: Agent.Agent.__init__

setName(self, name)

source code 

Sets the name of this agent

Parameters:
  • name (str) - the unique ID for this agent
Overrides: Agent.Agent.setName

getState(self, feature)

source code 

Returns the current Distribution over the specified feature

Parameters:
  • feature (string)
Returns: Distribution

setState(self, feature, value)

source code 

Sets this entity's state value for the specified feature

Parameters:
  • feature (string)
  • value (either a float or a Distribution. If the value is a float, it is first converted into a point distribution.)

getObservation(self, name)

source code 

Returns the current Distribution over the specified observation flag

Parameters:
  • name (string)
Returns: Distribution

setObservation(self, name, value)

source code 

Sets this entity's observation flag for the observation type

Parameters:
  • name (string)
  • value (either a float or a Distribution. If the value is a float, it is first converted into a point distribution.)

getStateFeatures(self)

source code 
Returns: str[]
names of the valid state features

getEntity(self, name)

source code 
Parameters:
  • name (string)
Returns: RecursiveAgent
the agent representing the beliefs about the given entity

hasBelief(self, entity)

source code 
Parameters:
  • entity (str) - the name of the entity being queried about
Returns: boolean
True iff I have a belief about the named entity

getEntities(self)

source code 
Returns: str[]
the names of entities that I have beliefs about

getEntityBeliefs(self)

source code 
Returns: Agent[]
the subjective entity views that I have

getBeliefKeys(self)

source code 
Returns: StateKey[]
the state features across all beliefs that this agent has

getNestedBelief(self, keys)

source code 

Accesses a nested belief by following the branches specified by keys (a list of strings).

Warning: may not actually work anymore!

setEntity(self, entity)

source code 

Sets my belief about the given entity to be the provided entity object. Basically equivalent to self.entities[entity.name] = entity.

Parameters:

setRecursiveBelief(self, name, feature, value)

source code 

Helper method for setting the beliefs of a feature

Parameters:
  • name (str) - the name of the other entity about whom our belief is is subject to change.
  • feature (str) - the state feature to change
  • value - the new value for the named state feature

Note: this will change all of the subjective beliefs that this entityd holds. Thus, not only will my beliefs about name, but also my beliefs about X's beliefs about name.

getAllBeliefs(self)

source code 

Packages up all of this agent's beliefs into a handy dictionary

Returns: dict
the dictionary has the following indices:
  • state: what this agent believes about the state of the world
  • name: what this agent think agent, name, believes (i.e., a recursive call to getAllBeliefs)

applyPolicy(self, state=None, actions=[], history=None, debug=None, explain=False)

source code 

Generates a decision chosen according to the agent's current policy

Parameters:
  • state (Distribution(KeyedVector)) - the current state vector
  • actions (Action[]) - the possible actions the agent can consider (defaults to all available actions)
  • history (Action[]:bool) - a dictionary of actions that have already been performed (and which should not be performed again if they are labeled as not repeatable)
  • explain (bool) - flag indicating whether an explanation should be generated
Returns: (Action[],Element)
a list of actions and an explanation, the latter provided by execute

initialStateEstimator(self)

source code 

Initializes beliefs

Overrides: Agent.Agent.initialStateEstimator

preComStateEstimator(self, beliefs, actions, epoch=-1, debug=None)

source code 

Computes the hypothetical changes to the given beliefs in response to the given actions

Parameters:
  • beliefs (dict) - the beliefs to be updated (traditionally, the result from getAllBeliefs)
  • actions (dict:str→Action) - the actions observed by this agent
  • epoch (int) - the current epoch in which these observations occurred (currently ignored, but potentially important)
  • debug (Debugger)
Returns: dict
the belief changes that would result from the specified observed actions, in dictionary form:
Overrides: Agent.Agent.preComStateEstimator

incorporateMessage(self, msg, log=None)

source code 

Update an entity's beliefs in response to set of messages

Parameters:
  • msg (Message) - the message whose dynamics we wish to compute
  • log - not sure what this is for, probably auditing at some point, but nothing happens to it right now, so it's not very useful
Returns: KeyedMatrix
the dynamics matrix corresponding to the desired change of beliefs implied by the given message

__incorporateMessage(self, factor)

source code 

Update an entity's beliefs in response to a received message

Parameters:
  • factor (dict) - the individual message factor
Returns: KeyedMatrix
the dynamics corresponding to an individual factor

getObservations(self)

source code 
Returns: list
the sequence of events that this entity has witnessed

findObservation(self, action, depth=0)

source code 

Returns true iff the agent has observed the given action

Parameters:
  • action (Action) - the observation to look for
  • depth (int) - the maximum number of steps to look into the past (by default, look arbitrarily far)
Returns: a tuple (boolean,int)
the first return value is true iff the agent has observed the given action within the past depth time steps. The second return value is the number of steps in the past that the observation occurs. This value is negative if no such observation is found within the specified depth.

observe(self, actionDict={})

source code 
Parameters:
  • actionDict (dict:str→Action[]) - the performed actions, indexed by actor name
Returns: dict
observations this entity would make of the given actions, in the same format as the provided action dictionary

getActionKeys(self)

source code 
Returns: teamwork.math.Keys.ActionKey[]
the minimal set of observations relevant to this agent

multistep(self, horizon=1, start={}, state=None, debug=None)

source code 

Steps this entity the specified number of steps into the future (where a step is one entity performing its policy-specified action)

Parameters:

Warning: This method still needs to be handed an updated turn vector

step(self, actDict, state=None, debug=None)

source code 

Modifies the current entity in response to the policy-driven actions selected by the provided dictionary of entities.

Parameters:

getDynamics(self, act, feature)

source code 
Parameters:
  • act (Action) - the action whose effect we are interested in
  • feature (str) - if the optional feature argument is provided, then this method returns the dynamics for only the given feature; otherwise, returns the effect over all state features (but this latter capability is now deprecated)
Returns: PWLDynamics
this entity's dynamics model for the given action

applyChanges(self, beliefs, delta, descend=1, rewind=0)

source code 

Takes changes and modifies the given beliefs accordingly

Parameters:
  • descend (boolean) - If the descend flag is set, then the recursive changes in the delta will also be applied.
  • rewind (boolean) - If the rewind flag is set, then the changes will be undone, instead of applied.

freeze(self)

source code 

Takes the current state of beliefs and marks it as the initial, beginning-of-the-world state of beliefs.

Note: as a side effect, it resets the observation history

ancestry(self)

source code 
Returns: str
a string representation of this entity's position in the recursive belief tree.
  • If self.parent == None, then returns self.name
  • Otherwise, returns self.parent.ancestry()+'->'+self.name

beliefDepth(self)

source code 
Returns: int
the recursive depth of the current entity (0 is the depth of a root entity)

__copy__(self)

source code 
Overrides: Agent.Agent.__copy__

Warning: the dynamics are not copied, but simply linked

__eq__(self, entity)
(Equality operator)

source code 

Equality test between agents

Parameters:
Returns: boolean

Warning: only partially implemented

__xml__(self)

source code 
Overrides: Agent.Agent.__xml__

parse(self, element)

source code 

Extracts this agent's recursive belief structure from the given XML Element

Parameters:
  • element (Element)
Overrides: Agent.Agent.parse

Instance Variable Details [hide private]

relationships

inter-agent relationships from this agent. In dictionary form:
  • relationship name: list of agent names