XMLBIF¶
- class pgmpy.readwrite.XMLBIF.XMLBIFReader(path=None, string=None)[source]¶
Initialisation of XMLBIFReader object.
- Parameters:
Examples
# xmlbif_test.xml is the file present in # http://www.cs.cmu.edu/~fgcozman/Research/InterchangeFormat/ >>> from pgmpy.readwrite import XMLBIFReader >>> reader = XMLBIFReader(“xmlbif_test.xml”) >>> model = reader.get_model()
Reference¶
[1] https://www.cs.cmu.edu/afs/cs/user/fgcozman/www/Research/InterchangeFormat/
- get_edges()[source]¶
Returns the edges of the network
Examples
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml") >>> reader.get_edges() [['family-out', 'light-on'], ['family-out', 'dog-out'], ['bowel-problem', 'dog-out'], ['dog-out', 'hear-bark']]
- get_model(state_name_type=<class 'str'>)[source]¶
Returns a Bayesian Network instance from the file/string.
- Parameters:
state_name_type (int, str, or bool (default: str)) – The data type to which to convert the state names of the variables.
- Returns:
BayesianNetwork instance
- Return type:
The read model.
Examples
>>> from pgmpy.readwrite import XMLBIFReader >>> reader = XMLBIFReader("xmlbif_test.xml") >>> model = reader.get_model()
- get_parents()[source]¶
Returns the parents of the variables present in the network
Examples
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml") >>> reader.get_parents() {'bowel-problem': [], 'dog-out': ['family-out', 'bowel-problem'], 'family-out': [], 'hear-bark': ['dog-out'], 'light-on': ['family-out']}
- get_property()[source]¶
Returns the property of the variable
Examples
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml") >>> reader.get_property() {'bowel-problem': ['position = (190, 69)'], 'dog-out': ['position = (155, 165)'], 'family-out': ['position = (112, 69)'], 'hear-bark': ['position = (154, 241)'], 'light-on': ['position = (73, 165)']}
- get_states()[source]¶
Returns the states of variables present in the network
Examples
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml") >>> reader.get_states() {'bowel-problem': ['true', 'false'], 'dog-out': ['true', 'false'], 'family-out': ['true', 'false'], 'hear-bark': ['true', 'false'], 'light-on': ['true', 'false']}
- get_values()[source]¶
Returns the CPD of the variables present in the network
Examples
>>> reader = XMLBIF.XMLBIFReader("xmlbif_test.xml") >>> reader.get_values() {'bowel-problem': array([[ 0.01], [ 0.99]]), 'dog-out': array([[ 0.99, 0.01, 0.97, 0.03], [ 0.9 , 0.1 , 0.3 , 0.7 ]]), 'family-out': array([[ 0.15], [ 0.85]]), 'hear-bark': array([[ 0.7 , 0.3 ], [ 0.01, 0.99]]), 'light-on': array([[ 0.6 , 0.4 ], [ 0.05, 0.95]])}
- class pgmpy.readwrite.XMLBIF.XMLBIFWriter(model, encoding='utf-8', prettyprint=True)[source]¶
Initialise a XMLBIFWriter object.
- Parameters:
model (BayesianNetwork Instance) – Model to write
encoding (str (optional)) – Encoding for text data
prettyprint (Bool(optional)) – Indentation in output XML if true
Examples
>>> from pgmpy.readwrite import XMLBIFWriter >>> from pgmpy.utils import get_example_model >>> model = get_example_model('asia') >>> writer = XMLBIFWriter(model) >>> writer.write_xmlbif('asia.xml')
Reference¶
[1] https://www.cs.cmu.edu/afs/cs/user/fgcozman/www/Research/InterchangeFormat/
- get_definition()[source]¶
Add Definition to XMLBIF
- Returns:
dict
- Return type:
dict of type {variable: definition tag}
Examples
>>> writer = XMLBIFWriter(model) >>> writer.get_definition() {'hear-bark': <Element DEFINITION at 0x7f1d48977408>, 'family-out': <Element DEFINITION at 0x7f1d489773c8>, 'dog-out': <Element DEFINITION at 0x7f1d48977388>, 'bowel-problem': <Element DEFINITION at 0x7f1d48977348>, 'light-on': <Element DEFINITION at 0x7f1d48977448>}
- get_properties()[source]¶
Add property to variables in XMLBIF
- Returns:
dict
- Return type:
dict of type {variable: property tag}
Examples
>>> writer = XMLBIFWriter(model) >>> writer.get_property() {'light-on': <Element PROPERTY at 0x7f7a2ffac1c8>, 'family-out': <Element PROPERTY at 0x7f7a2ffac148>, 'hear-bark': <Element PROPERTY at 0x7f7a2ffac188>, 'bowel-problem': <Element PROPERTY at 0x7f7a2ffac0c8>, 'dog-out': <Element PROPERTY at 0x7f7a2ffac108>}
- get_states()[source]¶
Add outcome to variables of XMLBIF
- Returns:
dict
- Return type:
dict of type {variable: outcome tags}
Examples
>>> writer = XMLBIFWriter(model) >>> writer.get_states() {'dog-out': [<Element OUTCOME at 0x7ffbabfcdec8>, <Element OUTCOME at 0x7ffbabfcdf08>], 'family-out': [<Element OUTCOME at 0x7ffbabfd4108>, <Element OUTCOME at 0x7ffbabfd4148>], 'bowel-problem': [<Element OUTCOME at 0x7ffbabfd4088>, <Element OUTCOME at 0x7ffbabfd40c8>], 'hear-bark': [<Element OUTCOME at 0x7ffbabfcdf48>, <Element OUTCOME at 0x7ffbabfcdf88>], 'light-on': [<Element OUTCOME at 0x7ffbabfcdfc8>, <Element OUTCOME at 0x7ffbabfd4048>]}
- get_values()[source]¶
Add Table to XMLBIF.
- Returns:
dict
- Return type:
dict of type {variable: table tag}
Examples
>>> writer = XMLBIFWriter(model) >>> writer.get_values() {'dog-out': <Element TABLE at 0x7f240726f3c8>, 'light-on': <Element TABLE at 0x7f240726f488>, 'bowel-problem': <Element TABLE at 0x7f240726f388>, 'family-out': <Element TABLE at 0x7f240726f408>, 'hear-bark': <Element TABLE at 0x7f240726f448>}
- get_variables()[source]¶
Add variables to XMLBIF
- Returns:
dict
- Return type:
dict of type {variable: variable tags}
Examples
>>> writer = XMLBIFWriter(model) >>> writer.get_variables() {'bowel-problem': <Element VARIABLE at 0x7fe28607dd88>, 'family-out': <Element VARIABLE at 0x7fe28607de08>, 'hear-bark': <Element VARIABLE at 0x7fe28607de48>, 'dog-out': <Element VARIABLE at 0x7fe28607ddc8>, 'light-on': <Element VARIABLE at 0x7fe28607de88>}
- write_xmlbif(filename)[source]¶
Write the xml data into the file.
- Parameters:
filename (Name of the file.)
Examples
>>> from pgmpy.readwrite import XMLBIFWriter >>> from pgmpy.utils import get_example_model >>> model = get_example_model('asia') >>> writer = XMLBIFWriter(model) >>> writer.write_xmlbif('asia.xml')