XDSLReader#

class pgmpy.readwrite.XDSLReader(path=None, string=None)[source]#

Bases: object

Initializes the reader object for XDSL file formats[1] created through GeNIe[2]. Note that XDSLReader only supports cpt blocks from the XDSL file format; elements like ‘deterministic’ need to be aapropriately converted into ‘cpt’ elements before usage.

Parameters:
pathfile or str

Path to the XDSL file.

stringstr

A string containing the XDSL file content.

Examples

>>> # AsiaDiagnosis.xdsl is an example file downloadable from
>>> # https://repo.bayesfusion.com/bayesbox.html
>>> # The file has been modified slightly to adhere to XDSLReader requirements
>>> from pgmpy.readwrite import XDSLReader
>>> reader = XDSLReader("AsiaDiagnosis.xdsl")
>>> model = reader.get_model()
get_edges()[source]#

Returns the edges of the network

Examples

>>> reader = XDSLReader("AsiaDiagnosis.xdsl")
>>> reader.get_edges()
[['asia', 'tub'],
['smoke', 'lung'],
['tub', 'either'],
['lung', 'either'],
['either', 'xray'],
['smoke', 'bronc'],
['either', 'dysp'],
['bronc', 'dysp']]
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:
DiscreteBayesianNetwork instance: The read model.

Examples

>>> from pgmpy.readwrite import XDSLReader
>>> reader = XDSLReader("AsiaDiagnosis.xdsl")
>>> model = reader.get_model()
get_parents()[source]#

Returns the parents of the variables present in the network

Examples

>>> reader = XDSLReader("AsiaDiagnosis.xdsl")
>>> reader.get_parents()
{'asia': [],
'tub': ['asia'],
'smoke': [],
'lung': ['smoke'],
'either': ['tub', 'lung'],
'xray': ['either'],
'bronc': ['smoke'],
'dysp': ['either', 'bronc']
}
get_states()[source]#

Returns the states of variables present in the network

Examples

>>> reader = XDSLReader("AsiaDiagnosis.xdsl")
>>> reader.get_states()
{'asia': ['no', 'yes'],
'tub': ['no', 'yes'],
'smoke': ['no', 'yes'],
'lung': ['no', 'yes'],
'either': ['Nothing',
'CancerORTuberculosis'],
'xray': ['Normal', 'Abnormal'],
'bronc': ['Absent', 'Present'], '
dysp': ['Absent', 'Present']
}
get_values()[source]#

Returns the CPD of the variables present in the network

Examples

>>> reader = XDSLReader("AsiaDiagnosis.xdsl")
>>> reader.get_values()
{'asia': [[0.99], [0.01]],
'tub': [[0.99, 0.95], [0.01, 0.05]],
'smoke': [[0.5], [0.5]],
'lung': [[0.99, 0.9], [0.01, 0.1]],
'either': [[1.0, 1.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],
'xray': [[0.95, 0.02], [0.05, 0.98]],
'bronc': [[0.7, 0.4], [0.3, 0.6]],
'dysp': [[0.9, 0.2, 0.3, 0.1], [0.1, 0.8, 0.7, 0.9]]
}
get_variables()[source]#

Returns list of variables of the network

Examples

>>> reader = XDSLReader("AsiaDiagnosis.xdsl")
>>> reader.get_variables()
['asia', 'tub', 'smoke', 'lung', 'either', 'xray', 'bronc', 'dysp']