XBNReader#
- class pgmpy.readwrite.XBNReader(path=None, string=None)[source]#
Bases:
objectInitializer for XBNReader class.
- Parameters:
- path: str or file
Path of the file containing XBN data.
- string: str
String of XBN data
Examples
>>> reader = XBNReader("test_XBN.xml")
- get_analysisnotebook_values()[source]#
Returns a dictionary of the attributes of ANALYSISNOTEBOOK tag
Examples
>>> reader = XBNReader("xbn_test.xml") >>> reader.get_analysisnotebook_values() {'NAME': "Notebook.Cancer Example From Neapolitan", 'ROOT': "Cancer"}
- get_bnmodel_name()[source]#
Returns the name of the BNMODEL.
Examples
>>> reader = XBNReader("xbn_test.xml") >>> reader.get_bnmodel_name() 'Cancer'
- get_distributions()[source]#
Returns a dictionary of name and its distribution. Distribution is a ndarray.
The ndarray is stored in the standard way such that the rightmost variable changes most often. Consider a CPD of variable ‘d’ which has parents ‘b’ and ‘c’ (distribution[‘CONDSET’] = [‘b’, ‘c’])
Examples
>>> reader = XBNReader("xbn_test.xml") >>> reader.get_distributions() {'a': {'TYPE': 'discrete', 'DPIS': array([[ 0.2, 0.8]])}, 'e': {'TYPE': 'discrete', 'DPIS': array([[ 0.8, 0.2], [ 0.6, 0.4]]), 'CONDSET': ['c'], 'CARDINALITY': [2]}, 'b': {'TYPE': 'discrete', 'DPIS': array([[ 0.8, 0.2], [ 0.2, 0.8]]), 'CONDSET': ['a'], 'CARDINALITY': [2]}, 'c': {'TYPE': 'discrete', 'DPIS': array([[ 0.2 , 0.8 ], [ 0.05, 0.95]]), 'CONDSET': ['a'], 'CARDINALITY': [2]}, 'd': {'TYPE': 'discrete', 'DPIS': array([[ 0.8 , 0.2 ], [ 0.9 , 0.1 ], [ 0.7 , 0.3 ], [ 0.05, 0.95]]), 'CONDSET': ['b', 'c']}, 'CARDINALITY': [2, 2]}
- get_edges()[source]#
Returns a list of tuples. Each tuple contains two elements (parent, child) for each edge.
Examples
>>> reader = XBNReader("xbn_test.xml") >>> reader.get_edges() [('a', 'b'), ('a', 'c'), ('b', 'd'), ('c', 'd'), ('c', 'e')]
- get_static_properties()[source]#
Returns a dictionary of STATICPROPERTIES
Examples
>>> reader = XBNReader("xbn_test.xml") >>> reader.get_static_properties() {'FORMAT': 'MSR DTAS XML', 'VERSION': '0.2', 'CREATOR': 'Microsoft Research DTAS'}
- get_variables()[source]#
Returns a list of variables.
Examples
>>> reader = XBNReader("xbn_test.xml") >>> reader.get_variables() {'a': {'TYPE': 'discrete', 'XPOS': '13495', 'YPOS': '10465', 'DESCRIPTION': '(a) Metastatic Cancer', 'STATES': ['Present', 'Absent']} 'b': {'TYPE': 'discrete', 'XPOS': '11290', 'YPOS': '11965', 'DESCRIPTION': '(b) Serum Calcium Increase', 'STATES': ['Present', 'Absent']}, 'c': {....}, 'd': {....}, 'e': {....} }