Node
Created on Mon Feb 18 10:42:34 2013
Copyright (C) 2013 James Bono
GNU Affero General Public License
-
class pynfg.classes.node.Node(name, parents, continuous)[source]
Implements a generic node of the semi-NFG formalism created by D. Wolpert
Note
This is the superclass. Nodes are generally instantiated in one of the
subclasses, ChanceNode, DecisionNode or DeterNode.
Parameters: |
- name (str) – the name of the Node, usually descriptive, e.g. C5 for
the fifth chance node (C for chance), or C21 for the second chance node
in the first time step, etc.
- parents (list) – a list of the Node’s parents
- continuous (bool) – True if Node takes on continuous values. False if
discrete.
|
Upon initialization, the following private method is called:
nodes.DeterNode._set_parent_dict()
Some useful methods are:
- classes.Nodes.dict2list_vals()
- classes.Nodes.get_CPTindex()
-
dict2list_vals(parentinput=None, valueinput=None)[source]
Convert parent/value dict entered by user to a list of values
Parameters: |
- parentinput (dict) – Optional. Specify values of the parents. Keys are
parent names. Values are parent values. To specify values for only a
subset of the parents, only enter those parents in the dictionary.
If only a subset of parent values are specified, then the current
values are used for the remaining parents.
- valueinput – Optional. A legitimate value of the decision node
object. If no valueinput is specified, then the output does not
include a value for the node itself.
|
Returns: | a list of the values for the parents and the decision node
itself in the order determine by the :py:attr:DecisionNode.parents`
OrderedDict.
|
-
get_CPTindex(parentinput=None, valueinput=None)[source]
Get the CPT index of (parent[, node]) values from user-supplied dict
Parameters: |
- parentinput (dict or list) – Optional. Specify values of the parents. If input is
dict, keys are parent names. Values are parent values. To specify
values for only a subset of the parents, only enter those parents
in the dictionary. If only a subset of parent values are specified,
then the current values are used for the remaining parents. If input
is list, then the list members are valid values of the parents, and
the order is given by the parent dictionary.
- valueinput – Optional. A legitimate value of the decision node
object. If no valueinput is specified, then the output
includes the current value for the node itself. If False is given,
then the output index does not include an entry for the node itself.
|
Returns: | a tuple CPT index for the values for the parents and the node
itself in the order determined by the parents OrderedDict.
|
-
get_value(index=None)[source]
Get the current value of the Node object
-
get_valueindex(value=None)[source]
Get the valueindex attribute of the discrete Node object
Parameters: | value – a legitimate value of the Node object, i.e. the value must
be in classes.Node.space. Otherwise an error occurs. If
no value is provided, the current valueindex is returned. |
Returns: | the index of the supplied value in the node’s space |
-
set_value(value)[source]
Set the current value of the Node object
Parameters: | value – a legitimate value of the Node object, i.e. the
value must be in classes.Node.space. |
Warning
When arbitrarily setting values, some children may have zero
probability given their parents. This means the logprob may be -inf.
If using, seminfg.SemiNFG.loglike(), this results in a
divide by zero error.
-
set_valueindex(index)[source]
Set the valueindex attribute of the discrete Node object
Parameters: | index (int) – the index for the current value |