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

Class PWLAgent

source code

Agent.Agent --+
              |
             PWLAgent

Lightweight version of a PsychSim agent with only the barest essentials for generating behaviors

Nested Classes [hide private]

Inherited from Agent.Agent: actionClass

Instance Methods [hide private]
 
__init__(self, agent=None)
Constructor that creates a lightweight version of a given PsychSim agent
source code
 
setHierarchy(self, classes)
We don't need no stinking defaults
source code
str
ancestry(self)
Returns: a string representation of this entity's position in the recursive belief tree.
source code
boolean
instanceof(self, className)
Returns: True iff this entity is a member of the specified class
source code
str[]
getStateFeatures(self)
Returns: names of the valid state features
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
 
getEntities(self) source code
 
getEntity(self, name) source code
 
getEntityBeliefs(self) source code
StateKey[]
getBeliefKeys(self)
Returns: the state features across all beliefs that this agent has
source code
str[]
getLinkTypes(self)
Returns: all of the available dynamics relationship types that his entity has
source code
str[]
getLinkees(self, relationship)
Returns: the others to which this entity has explicit relationships of the specified type
source code
LinkKey
getLinkKey(self, relation, entity)
Returns: the vector index for this entity's relation to the given entity
source code
float
getLink(self, relationship, entity)
Returns: the current value of the link
source code
 
setLink(self, relationship, entity, value) source code
 
initialStateEstimator(self)
Generates the initial belief state for the specified agent
source code
Distribution
getBelief(self, entity, feature)
Returns: the agent's current belief about the given entity's value for the given state feature
source code
 
setBelief(self, entity, feature, value)
Sets this entity's belief value for the specified entity's state feature value
source code
 
getGoals(self) source code
 
getGoalVector(self) source code
(Action[],Element)
applyPolicy(self, state=None, actions=[], history=None, debug=None, explain=False, entities={}, cache={})
Generates a decision chosen according to the agent's current policy
source code
 
actionValue(self, actions, horizon=1, state=None, debug=False)
Compute the expected value of performing the given action
source code
Distribution(KeyedVector)
stateEstimator(self, beliefs=None, actions=[], observation=None)
Updates the agent's beliefs in response to the given agents
source code
 
setEstimator(self, trans, obs)
Compute state estimator
source code
PWLDynamics
getDynamics(self, act, feature, cache=False, debug=False)
Returns: this entity's dynamics model for the given action
source code
 
__xml__(self, dynamics=False) source code
 
parse(self, element) source code

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

Class Variables [hide private]
  _supportFeature = 'likes'
the label for the liking relationship
  _trustFeature = 'trusts'
the label for the trust relationship
Instance Variables [hide private]
bool compiled
if True, the value function is compiled (default is False
str→(str→PWLDynamics) dynamics
a dictionary of dictionaries of PWLDynamics objects.
KeyedVector goals
this agent's goal weights
KeyedVector liking
the liking this agent has for others
  parent
the parent of this agent, included for compatibility with RecursiveAgent instances.
PolicyTable policy
this agent's policy of behavior
  relationships
an empty dictionary of inter-agent relationships from this agent
KeyedVector trust
the trust this agent has in others

Inherited from Agent.Agent: actions, name, omega

Method Details [hide private]

__init__(self, agent=None)
(Constructor)

source code 

Constructor that creates a lightweight version of a given PsychSim agent

Parameters:
  • agent - the RecursiveAgent to be distilled (if omitted, an empty agent is created)
Overrides: Agent.Agent.__init__

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

instanceof(self, className)

source code 
Parameters:
  • className (str) - name of class to test against
Returns: boolean
True iff this entity is a member of the specified class

getStateFeatures(self)

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

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.)

getBeliefKeys(self)

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

getLinkTypes(self)

source code 
Returns: str[]
all of the available dynamics relationship types that his entity has

getLinkees(self, relationship)

source code 
Parameters:
  • relationship (str) - the dynamic relationship (e.g., 'likes', 'trusts') to evaluate
Returns: str[]
the others to which this entity has explicit relationships of the specified type

getLinkKey(self, relation, entity)

source code 
Returns: LinkKey
the vector index for this entity's relation to the given entity

getLink(self, relationship, entity)

source code 
Parameters:
  • relationship - the dynamic relationship (e.g., 'likes', 'trusts') to evaluate
  • entity - the entity who is the object of the relationship (e.g., the entity being liked or trusted)
  • relationship,entity (str)
Returns: float
the current value of the link

setLink(self, relationship, entity, value)

source code 
Parameters:
  • relationship - the dynamic relationship (e.g., 'likes', 'trusts') to evaluate
  • entity - the entity who is the object of the relationship (e.g., the entity being liked or trusted)
  • value (float) - the new value for my trust level
  • relationship,entity (str)

initialStateEstimator(self)

source code 

Generates the initial belief state for the specified agent

Overrides: Agent.Agent.initialStateEstimator

getBelief(self, entity, feature)

source code 
Parameters:
  • entity (str) - the name of the relevant entity
  • feature (str) - the state feature of interest
Returns: Distribution
the agent's current belief about the given entity's value for the given state feature

setBelief(self, entity, feature, value)

source code 

Sets this entity's belief value for the specified entity's state feature value

Parameters:
  • entity (str) - the name of the relevant entity
  • feature (string) - the state feature of interest
  • value (either a float or a Distribution. If the value is a float, it is first converted into a point distribution.)

applyPolicy(self, state=None, actions=[], history=None, debug=None, explain=False, entities={}, cache={})

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
  • entities - a dictionary of entities to be used as a value tree cache
  • cache - values computed so far
Returns: (Action[],Element)
a list of actions and an explanation, the latter provided by execute

actionValue(self, actions, horizon=1, state=None, debug=False)

source code 

Compute the expected value of performing the given action

Parameters:
  • actions (Action[]) - the actions whose effect we want to evaluate
  • horizon (int) - the length of the forward projection
  • state (Distribution) - the world state to evaluate the actions in (defaults to current world state)

Warning: Computation assumes that dynamics for instantiated actions are already stored. Missing dynamics are taken to imply no effect.

stateEstimator(self, beliefs=None, actions=[], observation=None)

source code 

Updates the agent's beliefs in response to the given agents

Parameters:
  • beliefs (Distribution(KeyedVector)) - the agent's current beliefs (typically self.beliefs)
  • actions (Action[]) - the observed actions
  • obersvation - if in a partially observable domain, this is the observation received (default is None)
  • observation (str)
Returns: Distribution(KeyedVector)
the new beliefs (updates the agent's beliefs as a side effect)

getDynamics(self, act, feature, cache=False, debug=False)

source code 
Parameters:
  • act (Action) - the action whose effect we are interested in
  • feature (str) - the feature whose effect we want to get the dynamics for
  • cache (bool) - if True, then save the instantiated dynamics for future recall (default is False)
  • debug (bool) - if True, prints out some debugging statements (default is False
Returns: PWLDynamics
this entity's dynamics model for the given action

__xml__(self, dynamics=False)

source code 
Parameters:
  • dynamcis - if True, instantiated dynamics are stored as well (default is False
  • dynamics (bool)
Overrides: Agent.Agent.__xml__

parse(self, element)

source code 
Overrides: Agent.Agent.parse

Instance Variable Details [hide private]

dynamics

a dictionary of dictionaries of PWLDynamics objects. The top-level key is the state feature the dynamics affect. The keys at the level below are Action types.
Type:
str→(str→PWLDynamics)

parent

the parent of this agent, included for compatibility with RecursiveAgent instances. Always None.