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

Class NodeData

libpgm/nodedata.py:32–136  ·  view source on GitHub ↗

This class represents the node data for each node in a graph. If the Bayesian network is static, it contains the attribute *Vdata*. If the Bayesian network is dynamic, it contains two attributes, *initial_Vdata* and *twotbn_Vdata*. If the Bayesian network has hybrid CPDs, it contains the additi

Source from the content-addressed store, hash-verified

30from dictionary import Dictionary
31
32class NodeData(Dictionary):
33 '''
34 This class represents the node data for each node in a graph. If the Bayesian network is static, it contains the attribute *Vdata*. If the Bayesian network is dynamic, it contains two attributes, *initial_Vdata* and *twotbn_Vdata*. If the Bayesian network has hybrid CPDs, it contains the additional attribute *nodes*.
35
36 '''
37 def __init__(self):
38 self.Vdata = None
39 '''A dictionary of node data.'''
40 self.initial_Vdata = None
41 '''In dynamic graphs, a dictionary containing node data for the initial time interval.'''
42 self.twotbn_Vdata = None
43 '''In dynamic graphs, a dictionary containing node data for every time step interval after the first one.'''
44 self.nodes = None
45 '''In hybrid graphs, a dictionary of {key:value} pairs linking the name of each node (the key) to a clas instance (the value) which represents the node, its data, and its sampling function.'''
46
47
48 def load(self, path):
49 '''
50 Load node data from an input file located at *path*. Input file must be a plaintext .txt file with a JSON-style representation of a dict. The dict must have the top-level key ``Vdata`` or two top-level keys, ``initial_Vdata`` and ``twotbn_Vdata``. For example::
51
52 {
53 "Vdata": {
54 "<vertex 1>": <dict containing vertex 1 data>,
55 ...
56 "<vertex n>": <dict containing vertex n data>
57 }
58 }
59
60 or::
61
62 {
63 "initial_Vdata": {
64 "<vertex 1>": <dict containing vertex 1 data>,
65 ...
66 "<vertex n>": <dict containing vertex n data>
67 }
68 "twotbn_Vdata": {
69 "<vertex 1>": <dict containing vertex 1 data>,
70 ...
71 "<vertex n>": <dict containing vertex n data>
72 }
73 }
74
75 The function takes the following arguments:
76 1. *path* -- The path to the text file that contains input data (e.g., "mydictionary.txt")
77
78 In the static case, it modifies *Vdata* to hold the dictionary found at path. In the dynamic case, it modifies the *initial_Vdata* and *twotbn_Vdata* attributes to hold the dictionaries found at path.
79
80 ''&#x27;
81 self.dictload(path)
82
83 # try to load both for normal and dynamic cases
84 try:
85 self.Vdata = self.alldata["Vdata"]
86 except KeyError:
87 try:
88 self.initial_Vdata = self.alldata["initial_Vdata"]
89 self.twotbn_Vdata = self.alldata["twotbn_Vdata"]

Callers 12

timerFunction · 0.90
timerFunction · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
examples.pyFile · 0.90

Calls

no outgoing calls

Tested by 9

setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72