MCPcopy Create free account
hub / github.com/CyberPoint/libpgm / DynDiscBayesianNetwork

Class DynDiscBayesianNetwork

libpgm/dyndiscbayesiannetwork.py:34–183  ·  view source on GitHub ↗

This class represents a dynamic Bayesian network with discrete CPD tables. It contains the attributes *V*, *E*, *initial_Vdata*, and *twotbn_Vdata*, and the method *randomsample*.

Source from the content-addressed store, hash-verified

32from orderedskeleton import OrderedSkeleton
33
34class DynDiscBayesianNetwork(OrderedSkeleton):
35 '''
36 This class represents a dynamic Bayesian network with discrete CPD tables. It contains the attributes *V*, *E*, *initial_Vdata*, and *twotbn_Vdata*, and the method *randomsample*.
37
38 '''
39
40 def __init__(self, orderedskeleton=None, nodedata=None):
41 '''
42 This class can be called either with or without arguments. If it is called without arguments, none of its attributes are instantiated and it is left to the user to instantiate them manually. If it is called with arguments, the attributes will be loaded directly from the inputs. The arguments must be (in order):
43
44 1. *orderedskeleton* -- An instance of the :doc:`OrderedSkeleton <orderedskeleton>` or :doc:`GraphSkeleton <graphskeleton>` (as long as it&#x27;s ordered) class.
45 2. *nodedata* -- An instance of the :doc:`NodeData <nodedata>` class.
46
47 If these arguments are present, all attributes of the class (*V*, *E*, and *Vdata*) will be automatically copied from the graph skeleton and node data inputs.
48
49 This class requires that the *initial_Vdata* and *twotbn_Vdata* attributes get loaded with a dictionary with node data of the following fomat::
50
51 {
52 "initial_Vdata": {
53 "<vertex 1>": <dict containing vertex 1 data>,
54 ...
55 "<vertex n>": <dict containing vertex n data>
56 }
57 "twotbn_Vdata": {
58 "<vertex 1>": <dict containing vertex 1 data>,
59 ...
60 "<vertex n>": <dict containing vertex n data>
61 }
62 }
63
64 In particular, the ``"parents"`` attribute of ``"twotbn_Vdata"`` has the following format::
65
66 "twotbn_Vdata": {
67 "vertex": {
68 "parents": ["past_<vertex 1>",...,"past_<vertex n>", "vertex 1",..., "vertex m"]
69 ...
70 }
71 }
72
73 Where vertices 1 through *n* come from the previous time interval, and vertices 1 through *m* come from the current time interval. Note that additional keys besides the ones listed are possible in the dict of each vertex. For a full example see :doc:`unittestdyndict`.
74
75 Upon loading, the class will also check that the keys of *Vdata* correspond to the vertices in *V*.
76
77 ''&#x27;
78 if (orderedskeleton != None and nodedata != None):
79 try:
80 self.V = orderedskeleton.V
81 '''A list of the names of the vertices.'''
82 self.E = orderedskeleton.E
83 '''A list of [origin, destination] pairs of vertices that make edges.'''
84 self.initial_Vdata = nodedata.initial_Vdata
85 '''A dictionary containing CPD data for the Bayesian network at time interval 0.'''
86 self.twotbn_Vdata = nodedata.twotbn_Vdata
87 '''A dictionary containing CPD data for the Bayesian network for time intervals greater than 0.'''
88 except:
89 raise Exception, "Inputs were malformed; first arg must contain V and E attributes and second arg must contain initial_Vdata and twotbn_Vdata attributes."
90
91 # check that inputs match up

Callers 2

setUpMethod · 0.90
examples.pyFile · 0.90

Calls

no outgoing calls

Tested by 1

setUpMethod · 0.72