XBNWriter#

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

Bases: object

Initializer for XBNWriter class

Parameters:
model: DiscreteBayesianNetwork Instance

Model to write

encoding: str(optional)

Encoding for test data

prettyprint: Bool(optional)

Indentation in output XML if true

Examples

>>> writer = XBNWriter(model)
indent(elem, level=0)[source]#

Inplace prettyprint formatter.

set_analysisnotebook(**data)[source]#

Set attributes for ANALYSISNOTEBOOK tag

Parameters:
**data: dict

{name: value} for the attributes to be set.

Examples

>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_analysisnotebook(
...     NAME="Notebook.Cancer Example From Neapolitan", ROOT="Cancer"
... )
set_bnmodel_name(name)[source]#

Set the name of the BNMODEL.

Parameters:
name: str

Name of the BNModel.

Examples

>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_bnmodel_name("Cancer")
set_distributions()[source]#

Set distributions in the network.

Examples

>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_distributions()
set_edges(edge_list)[source]#

Set edges/arc in the network.

Parameters:
edge_list: array_like

list, tuple, dict or set whose each element has two values (parent, child).

Examples

>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_edges(
...     [("a", "b"), ("a", "c"), ("b", "d"), ("c", "d"), ("c", "e")]
... )
set_static_properties(**data)[source]#

Set STATICPROPERTIES tag for the network

Parameters:
**data: dict

{name: value} for name and value of the property.

Examples

>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_static_properties(
...     FORMAT="MSR DTAS XML", VERSION="0.2", CREATOR="Microsoft Research DTAS"
... )
set_variables(data)[source]#

Set variables for the network.

Parameters:
data: dict

dict for variable in the form of example as shown.

Examples

>>> from pgmpy.readwrite.XMLBeliefNetwork import XBNWriter
>>> writer = XBNWriter()
>>> writer.set_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"],
...         },
...     }
... )
write(filename)[source]#

Writes the BIF data into a file

Parameters:
filenameName of the file
write_xbn(filename)[source]#