Implements the DecisionNode class
Created on Mon Feb 18 10:31:17 2013
Copyright (C) 2013 James Bono
GNU Affero General Public License
Implements a decision node of the semi-NFG formalism by D. Wolpert
The classes.DecisionNode can be initialized with either a conditional probability distribution (CPT) or a distribution object from scipy.stats.distributions (discrete and continuous types are both supported).
Parameters: |
|
---|
Formally, a decision node has the following properties:
belongs to a human player
has a space of possible values.
- the conditional probability distribution from the values of its
parents - given by classes.DecisionNode.prob() or classes.ChanceNode.prob(), is not specified in the game. That distribution is given by the solution concept applied to the semi-NFG. This lack of CPDs at decision nodes is the reason the semi-NFG is said to be based on a semi-Bayes net.
Note
For a classes.DecisionNode, the parents nodes must be discrete.
Example:
import scipy.stats.distributions as randvars
dist1 = randvars.randint
params1 = [1, 4]
space1 = [1, 2, 3]
distip1 = (dist1, params1, space1)
C1 = ChanceNode('C1', distip=distip1, description='root CN given by randint 1 to 4')
D1 = DecisionNode('D1', '1', [-1, 0, 1], parents=[C1], description='This is a child node of C1')
Upon initialization, the following private method is called: classes.DecisionNode._set_parent_dict()
Some useful methods are:
Draw a value from the classes.DecisionNode object
Parameters: |
|
---|---|
Returns: | an element of classes.DecisionNode.space. |
Note
The values specified in parentinput must correspond to an item in the parent’s space attribute.
Warning
The CPT is an np.zero array upon initialization. Therefore, one must set the CPT wih classes.DecisionNode.randomCPT() or manually before calling this method.
Compute the conditional logprob of the current or specified value
Parameters: |
|
---|---|
Returns: | the conditional logprob of valueinput or the current value conditioned on parentinput or the current values of the parents. |
Note
If parent values are specified in parentinput, those values must correspond to items in the space attributes of the parents.
Warning
The CPT is an np.zero array upon initialization. Therefore, one must set the CPT wih classes.DecisionNode.randomCPT() or manually before calling this method.
Convert mixed CPT to pure CPT,
Parameters: | setCPT (bool) – if True (default), then the CPT attribute is converted to a pure CPT. Otherwise, the output is a pure CPT. |
---|
Note
whenever there are multiple argmax’s, each gets equal probability in the resuling “pure” CPT.
Create a perturbation of the CPT attribute.
Parameters: |
|
---|
Note
If setCPT is True, then there is no CPT output. If setCPT is True, and returnweight is False, then there is no output. If setCPT is True, and returnweight is True, then the weight is the only output. If setCPT is False, and returnweight is False, then the only output is the CPT output. Finally, if setCPT is False, and returnweight is True, then there is both CPT and weight output, and the weight is first in the list.
Compute the conditional probability of the current or specified value
Parameters: |
|
---|---|
Returns: | the conditional probability of valueinput or the current value conditioned on parentinput or the current values of the parents. |
Note
If parent values are specified in parentinput, those values must correspond to items in the space attributes of the parents.
Warning
The CPT is an np.zero array upon initialization. Therefore, one must set the CPT wih classes.DecisionNode.randomCPT() or manually before calling this method.
Create a random CPT for the classes.DecisionNode object
Parameters: |
|
---|---|
Returns: | a mixed or pure CPT. |