Package teamwork :: Package math :: Module ProbabilityTree :: Class ProbabilityTree
[hide private]
[frames] | no frames]

Class ProbabilityTree

source code

matrices.DecisionTree --+    
                        |    
      KeyedTree.KeyedTree --+
                            |
                           ProbabilityTree

A decision tree that supports probabilistic branches

If this node is not a probabilistic branch, then identical to a KeyedTree object.

Nested Classes [hide private]

Inherited from KeyedTree.KeyedTree: planeClass

Instance Methods [hide private]
 
fill(self, keys, value=0.0)
Fills in any missing slots with a default value
source code
 
freeze(self)
Locks in the dimensions and keys of all leaves
source code
 
unfreeze(self)
Unocks in the dimensions and keys of all leaves
source code
boolean
isProbabilistic(self)
Returns: true iff there's a probabilistic branch at this node
source code
ProbabilityTree[]
children(self)
Returns: all child nodes of this node
source code
 
branch(self, plane, falseTree=None, trueTree=None, pruneF=True, pruneT=True, prune=True, debug=False)
Same as KeyedTree.branch, except that plane can be a Distribution
source code
a new DecisionTree instance
_merge(self, other, op, comparisons=None, conditions=[])
Helper method that merges the two trees together using the given operator to combine leaf values, without pruning
source code
 
prune(self, comparisons=None, debug=False) source code
 
marginalize(self, key)
Marginalizes any distributions to remove the given key (not in place! returns the new tree)
source code
 
condition(self, observation) source code
 
instantiate(self, values) source code
 
instantiateKeys(self, values)
Replaces any key references by the values in the table
source code
 
generateAlternatives(self, index, value, test=None) source code
str
simpleText(self, printLeaves=True, numbers=True, all=False)
Returns a more readable string version of this tree
source code
 
updateKeys(self)
Updates the record of contained keys in self.keys
source code
 
__getitem__(self, index)
Returns: the distribution over leaf nodes for this value
source code
 
_multiply(self, other, comparisons=None, conditions=[]) source code
 
__str__(self) source code
 
__xml__(self) source code
 
parse(self, element, valueClass=None, debug=False)
Extracts the tree from the given XML element
source code

Inherited from KeyedTree.KeyedTree: getKeys, pruneIdentities, scale, toNumeric

Inherited from KeyedTree.KeyedTree (private): _instantiate, _keys

Inherited from matrices.DecisionTree: __add__, __copy__, __eq__, __hash__, __init__, __mul__, __neg__, __sub__, branches, count, createIndex, depth, fromRules, getPath, getValue, isLeaf, leafNodes, leaves, makeLeaf, makeRules, merge, rebalance, removeTautologies, replace

Inherited from matrices.DecisionTree (private): _extractTree

Class Variables [hide private]

Inherited from matrices.DecisionTree: checkPrune, checkTautology

Instance Variables [hide private]

Inherited from KeyedTree.KeyedTree: keys

Method Details [hide private]

fill(self, keys, value=0.0)

source code 

Fills in any missing slots with a default value

Parameters:
  • keys (list of Key instances) - the slots that should be filled
  • value - the default value (defaults to 0)
Overrides: KeyedTree.KeyedTree.fill

Note: does not overwrite existing values

freeze(self)

source code 

Locks in the dimensions and keys of all leaves

Overrides: KeyedTree.KeyedTree.freeze

unfreeze(self)

source code 

Unocks in the dimensions and keys of all leaves

Overrides: KeyedTree.KeyedTree.unfreeze

isProbabilistic(self)

source code 
Returns: boolean
true iff there's a probabilistic branch at this node

children(self)

source code 
Returns: ProbabilityTree[]
all child nodes of this node
Overrides: matrices.DecisionTree.children

branch(self, plane, falseTree=None, trueTree=None, pruneF=True, pruneT=True, prune=True, debug=False)

source code 

Same as KeyedTree.branch, except that plane can be a Distribution

Parameters:
Overrides: matrices.DecisionTree.branch

_merge(self, other, op, comparisons=None, conditions=[])

source code 

Helper method that merges the two trees together using the given operator to combine leaf values, without pruning

Parameters:
  • other (DecisionTree instance) - the other tree to merge with
  • op - the operator used to generate the new leaf values, lambda x,y:f(x,y) where x and y are leaf values
Returns: a new DecisionTree instance
Overrides: matrices.DecisionTree._merge

prune(self, comparisons=None, debug=False)

source code 
Overrides: matrices.DecisionTree.prune

marginalize(self, key)

source code 

Marginalizes any distributions to remove the given key (not in place! returns the new tree)

Parameters:
  • key - the key to marginalize over
Returns:
a new ProbabilityTree object representing the marginal function

Note: no exception is raised if the key is not present

instantiate(self, values)

source code 
Overrides: KeyedTree.KeyedTree.instantiate

instantiateKeys(self, values)

source code 

Replaces any key references by the values in the table

Overrides: KeyedTree.KeyedTree.instantiateKeys
(inherited documentation)

generateAlternatives(self, index, value, test=None)

source code 
Overrides: matrices.DecisionTree.generateAlternatives

simpleText(self, printLeaves=True, numbers=True, all=False)

source code 

Returns a more readable string version of this tree

Parameters:
  • printLeaves (boolean) - optional flag indicating whether the leaves should also be converted into a user-friendly string
  • numbers (boolean) - if True, floats are used to represent the threshold; otherwise, an automatically generated English representation (defaults to False)
Returns: str
Overrides: KeyedTree.KeyedTree.simpleText

updateKeys(self)

source code 

Updates the record of contained keys in self.keys

Overrides: KeyedTree.KeyedTree.updateKeys
(inherited documentation)

__getitem__(self, index)
(Indexing operator)

source code 
Returns:
the distribution over leaf nodes for this value
Overrides: matrices.DecisionTree.__getitem__

_multiply(self, other, comparisons=None, conditions=[])

source code 
Overrides: matrices.DecisionTree._multiply

__str__(self)
(Informal representation operator)

source code 
Overrides: matrices.DecisionTree.__str__

__xml__(self)

source code 
Overrides: matrices.DecisionTree.__xml__

parse(self, element, valueClass=None, debug=False)

source code 

Extracts the tree from the given XML element

Parameters:
  • element (Element) - The XML Element object specifying the plane
  • valueClass - The class used to generate the leaf values
Returns:
the ProbabilityTree instance
Overrides: matrices.DecisionTree.parse