Implements the ChanceNode class
Part of: PyNFG - a Python package for modeling and solving Network Form Games
Created on Mon Feb 18 10:35:19 2013
Copyright (C) 2013 James Bono
GNU Affero General Public License
Implements a chance node of the semi-NFG formalism created by D. Wolpert
The classes.ChanceNode 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: |
|
---|
Note
For a classes.ChanceNode based on a CPT, the parents must be discrete valued nodes. The dimensions of the CPT must correspond to the order of the parents. The order of the CPT in each dimension must correspond to the order of the parent space for that dimension.
Formally, a chance node has the following properties:
Example:
import pynfg
import scipy.stats.distributions as randvars
D1 = DecisionNode('D1', '1', [-1, 0, 1], parents=[],
description='This is a child node of C1')
dist1 = randvars.norm
params1 = [D1, 2]
distip1 = (dist1, params1)
C1 = ChanceNode('C1', distip=distip1,
description='CN norm rv with scale=2 and loc=D1')
or:
import pynfg
import scipy.stats.distributions as randvars
dist1 = randvars.randint
params1 = [5, 10]
distip1 = (dist1, params1)
C1 = ChanceNode('C1', distip=distip1,
description='root CN randint from 5 to 10')
dist2 = randvars.hypergeom
params2 = [C1, 3, 3]
space2 = [0, 1, 2, 3]
distip2 = (dist2, params2, space2)
C2 = ChanceNode('C2', distip=distip1,
description='CN hypergeom M=C1, n=3, N=3')
Upon initialization, the following private method is called: classes.ChanceNode._set_parent_dict()
Some useful methods are:
Draw a value from the classes.ChanceNode object
Parameters: |
|
---|---|
Returns: | an element of classes.ChanceNode.space if the ChanceNode object is discrete. For continuous ChanceNode objects, it returns a value at which the pdf is nonzero. |
Note
If parent values are specified in parentinput, those values must be legitimate values of the parent. For discrete parents, the values must correspond to an item in the parent’s space attribute.
Compute the conditional logprob of the current or specified value
Parameters: |
|
---|---|
Returns: | the log 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 be legitimate values of the parent. For discrete parents, the values must correspond to an item in the parent’s space attribute.
This is equivalent to np.log(ChanceNode.prob())
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 be legitimate values of the parent. For discrete parents, the values must correspond to an item in the parent’s space attribute.