# Deterministic Node¶

Implements the DeterNode class

Part of: PyNFG - a Python package for modeling and solving Network Form Games

Created on Mon Feb 18 10:34:13 2013

Copyright (C) 2013 James Bono

GNU Affero General Public License

class pynfg.classes.deternode.DeterNode(name, func, params, continuous, space=None, description='no description', time=None, basename=None, verbose=False)[source]

Implements a deterministic node for the semi-NFG formalism created by D. Wolpert

Parameters: name (str) – the name of the DeterNode, usually descriptive, e.g. F5 for the fifth deterministic node (F for fixed), or F21 for the second deterministic node in the first time step, etc. func (function) – a deterministic function - defined with defaults for each of its inputs. params (dict) – keys are input keywords for func, values are parents or fixed values if something other than defaults for non-parent inputs is desired. continuous (bool) – True if function takes on continuous values. False if discrete. space (list) – The list of elements in space if discrete. Empty list if continuous description (str.) – a description of the DeterNode, usually including a summary description of the function, space, parents and children. time (integer) – the timestep to which the node belongs. This is generally only used for seminfg.iterSemiNFG objects. basename (str.) – a reference to a theoretical node in the base or kernel.

Formally, a deterministic node has the following properties:

• belongs to the nature player

• has deterministic function from the values of its parents - given by

classes.DecisionNode.prob() or classes.ChanceNode.prob().

Note

Deterministic nodes are not a part of the Semi-NFG formalism. Their functionality is implicit in the relationship between stochastic parent nodes and their stochastic children, as is the convention in Bayesian Networks. They can be seen as deterministically transforming the values of parents into the parameters that are used by their children.

Example:

import scipy.stats.distributions as randvars

dist1 = randvars.norm
params1 = [0.5, 1]
distip1 = (dist1, params1)
C1 = ChanceNode('C1', distip=distip1,
description='CN given by norm loc=0.5, scale=1')

def func2(var1=1, var2=0):
r = np.sign(var1+var2)
return r

params2 = {'var1': C1}
continuous2 = False
space2 = [-1, 0, 1]
F2 = DeterNode('F2', func2, params2, continuous2, space=space2,
description='a disc. DeterNode child of C1')


Upon initialization, the following private method is called: classes.DeterNode._set_parent_dict()

Some useful methods are:

• classes.DeterNode.draw_value()
• classes.DeterNode.prob()
• classes.DeterNode.logprob()
draw_value(parentinput=None, setvalue=True)[source]

Draw a value from the classes.DeterNode object

This function computes the value of the deterministic node given the current values of the parents or with the values provided in pareninput

Parameters: parentinput (dict) – Optional. Specify values of the parents at which to compute values from the function governing the DeterNode. 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 no parent values are specified, then the current values of the parents are used. setvalue (bool) – (Optional) determines if the random draw replaces classes.DeterNode.value. True by default. the value of the deterministic node that corresponds to the parent values.

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.

logprob(parentinput=None, valueinput=None)[source]

Compute the conditional logprob of the current or specified value

Parameters: parentinput (dict) – Optional. Specify values of the parents at which to compute the logprob of the value of the DeterNode. 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 no parent values are specified, then the current values of the parents are used. valueinput – Optional. A legitimate value of the DeterNode object. If no valueinput is specified, then the current value of the node is used. 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.

Note

Since this is a deterministic node, the logprob is alwayseither zero or -inf.

This is equivalent to np.log(DeterNode.prob())

prob(parentinput=None, valueinput=None)[source]

Compute the probability of the current or specified value

Note that since this is a deterministic node, the probability is always either zero or one.

Parameters: parentinput (dict) – Optional. Specify values of the parents at which to compute the probability of the value of the DeterNode function. 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 no parent values are specified, then the current values of the parents are used. valueinput – Optional. A legitimate value of the DeterNode object. If no valueinput is specified, then the current value of the node is used. 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.

Decision Node

Game Classes