Package teamwork :: Package policy :: Module pwlTable :: Class PWLTable
[hide private]
[frames] | no frames]

Class PWLTable

source code

Known Subclasses:

Tabular representation of a PWL function, as an alternative to KeyedTree

Instance Methods [hide private]
 
__init__(self) source code
 
reset(self)
Clears all existing contents (including attributes) of the table
source code
 
initialize(self)
Clears all existing contents (excluding attributes) of the table
source code
int
addAttribute(self, obj, value)
Inserts the new attribute/value into the LHS conditions for this policy
source code
 
delAttribute(self, index)
Deletes the attribute in the given position and reorganizes the rules accordingly
source code
int
index(self, state, observations={})
Returns: the rule index corresponding to the given beliefs
source code
 
__getitem__(self, index)
Shortcut method, index is either an int (for directly indexing into the table) or a belief vector.
source code
int
subIndex(self, attr, value)
Computes the index corresponding to the given value for the given attribute
source code
bool
consistentp(self, assignment, subIndex)
Tests whether extending a partial LHS assignment with a given subIndex is self-consistent
source code
int[]
factored2index(self, factors, check=False)
Transforms a list of subindices into a list of matching rule indices
source code
int[]
OLDfactored2index(self, factors)
Transforms a list of subindices into a list of matching rule indices
source code
int[]
index2factored(self, index)
Transforms a rule index into a list of subindices
source code
 
fromTree(self, tree)
Extract a tabular representation of the given PWL tree.
source code
PWLTable
getTable(self)
Returns: the base table (stripped of any subclass extras)
source code
 
_consistent(self, attr1, great1, attr2, great2=None, debug=False)
Compares an attribute-value pair against another (or others) to determine whether they're potentially consistent
source code
 
prune(self, rulesOnly=False, debug=False)
Removes rows and attributes that are irrelevant
source code
 
pruneRules(self, debug=False) source code
 
pruneAttributes(self, rulesOnly=False, debug=False)
Prune irrelevant attributes
source code
PWLTable
max(self, debug=False)
Computes the rules based on maximizing the values in this table
source code
PWLTable
star(self)
Computes the optimal value function, independent of action
source code
 
__copy__(self) source code
 
copy(self, result) source code
 
__len__(self) source code
 
__add__(self, other, debug=False) source code
 
__mul__(self, other, combiner=None, debug=False) source code
 
mergeZero(self, other, combiner=None, projector=None, debug=False)
Merging when both tables have all of their hyperplanes going through the origin
source code
int[]
mapIndex(self, other, factors, result=None, multiplicand=None, debug=False)
Translates an index in another table into one for this table
source code
 
__str__(self) source code
str
_ruleString(self)
Helper method that returns a string representation of the rules
source code
str
valueString(self)
Helper method that returns string representation of value function
source code
str
_attributeHeader(self, rhsLabel='Action')
Helper method that returns column headings for the attributes
source code
 
factorString(self, factors)
Helper method that returns string representation of factor tuple
source code
Instance Variables [hide private]
KeyedVector→int _attributes
mapping from LHS condition to position in attributes list
int→int→bool _consistency
table of cached consistency checks among attribute values
KeyedVector[] attributes
the list of LHS conditions
  rules
table of RHS, in dictionary form, indexed by row number
int→dict values
table of value function, in dictionary form, indexed by row number
bool zeroPlanes
True iff all of the attributes are hyperplanes through the origin
Method Details [hide private]

addAttribute(self, obj, value)

source code 

Inserts the new attribute/value into the LHS conditions for this policy

Parameters:
  • obj - the condition
  • value - the test value
Returns: int
the index of the attribute

delAttribute(self, index)

source code 

Deletes the attribute in the given position and reorganizes the rules accordingly

Parameters:
  • index (int) - the position of the attribute to be deleted within the list of attributes

Warning: it does not do any clever aggregation over multiple rules that may be collapsed because of the deletion of this attribute

index(self, state, observations={})

source code 
Parameters:
  • state - the beliefs to use in identifying the appropriate rule
Returns: int
the rule index corresponding to the given beliefs

__getitem__(self, index)
(Indexing operator)

source code 

Shortcut method, index is either an int (for directly indexing into the table) or a belief vector. Can't incorporate observations.

subIndex(self, attr, value)

source code 

Computes the index corresponding to the given value for the given attribute

Parameters:
  • attr (int) - the index of the attribute
  • value - the actual value to determine the index of
Returns: int

consistentp(self, assignment, subIndex)

source code 

Tests whether extending a partial LHS assignment with a given subIndex is self-consistent

Parameters:
  • assignment (int[])
  • subIndex (int)
Returns: bool
True iff the sub-index is consistent with the current partial assignment

factored2index(self, factors, check=False)

source code 

Transforms a list of subindices into a list of matching rule indices

Parameters:
  • check (bool) - if True, then check consistency before returning indices (default is False)
  • factors (int[])
Returns: int[]

Note: subindex can be a list of subindices

OLDfactored2index(self, factors)

source code 

Transforms a list of subindices into a list of matching rule indices

Parameters:
  • factors (int[])
Returns: int[]

Note: subindex can be a list of subindices

index2factored(self, index)

source code 

Transforms a rule index into a list of subindices

Parameters:
  • index (int)
Returns: int[]

fromTree(self, tree)

source code 

Extract a tabular representation of the given PWL tree. Updates this tree to represent the same PWL function as the given tree.

Parameters:

getTable(self)

source code 
Returns: PWLTable
the base table (stripped of any subclass extras)

_consistent(self, attr1, great1, attr2, great2=None, debug=False)

source code 

Compares an attribute-value pair against another (or others) to determine whether they're potentially consistent

Parameters:
Returns:
False if never consistent, True if always consistent, None otherwise

prune(self, rulesOnly=False, debug=False)

source code 

Removes rows and attributes that are irrelevant

Parameters:
  • rulesOnly (bool) - if True, only the RHS of the rules need to be distinct, not the value function as well (default is False)

max(self, debug=False)

source code 

Computes the rules based on maximizing the values in this table

Returns: PWLTable
the table with the newly generated rules

Warning: assumes that the same option keys exist in every rule in the value function

star(self)

source code 

Computes the optimal value function, independent of action

Returns: PWLTable
a table with the optimal value as the rules' RHS, and no values

__mul__(self, other, combiner=None, debug=False)

source code 
Parameters:
  • combiner (lambda) - optional binary function for using in combining RHS matrices (default is multiplication, duh)

Warning: like matrix multiplication, not commutative

mergeZero(self, other, combiner=None, projector=None, debug=False)

source code 

Merging when both tables have all of their hyperplanes going through the origin

Parameters:
  • combiner (lambda) - optional binary function for using in combining RHS matrices (default is multiplication)
  • projector (lambda) - optional binary function for using in projecting my LHS attributes based on the RHS of the other

Warning: like matrix multiplication, not commutative

mapIndex(self, other, factors, result=None, multiplicand=None, debug=False)

source code 

Translates an index in another table into one for this table

Parameters:
  • other (PWLTable) - the other table
  • factors (int or int[]) - the index or factors of the rule to map
  • result (int[]) - previously determined factors that should be merged (default is None)
  • multiplicand (KeyedMatrix) - matrix used to scale any attributes (default is identity)
Returns: int[]
a list of attributes subindices, None if no consistent index exists

_attributeHeader(self, rhsLabel='Action')

source code 

Helper method that returns column headings for the attributes

Parameters:
  • rhsLabel (str) - column heading to use for RHS (default is 'Action')
Returns: str

factorString(self, factors)

source code 

Helper method that returns string representation of factor tuple

Parameters:
  • factors (int or int[]) - factors (or rule index)