XMLBIFWriter#

class pgmpy.readwrite.XMLBIFWriter(model, encoding='utf-8', prettyprint=True)[source]#

Bases: object

Initialise a XMLBIFWriter object.

Parameters:
model: DiscreteBayesianNetwork 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.example_models import load_model
>>> model = load_model("bnlearn/asia")
>>> writer = XMLBIFWriter(model)
>>> writer.write("asia.xml")
get_definition()[source]#

Add Definition to XMLBIF

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

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

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.

get_variables()[source]#

Add variables to XMLBIF

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>}
indent(elem, level=0)[source]#

Inplace prettyprint formatter.

write(filename)[source]#

Write the xml data into the file.

Parameters:
filename: Name of the file.

Examples

>>> from pgmpy.readwrite import XMLBIFWriter
>>> from pgmpy.example_models import load_model
>>> model = load_model("bnlearn/asia")
>>> writer = XMLBIFWriter(model)
>>> writer.write("asia.xml")
write_xmlbif(filename)[source]#