XDSL¶
- class pgmpy.readwrite.XDSL.XDSLReader(path=None, string=None)[source]¶
Initializes the reader object for XDSL file formats[1] created through GeNIe[2].
- Parameters:
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()
Reference¶
[1] https://support.bayesfusion.com/docs/GeNIe/saving_xdslfileformat.html [2] https://www.bayesfusion.com/genie/
- 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
- Return type:
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]] }
- class pgmpy.readwrite.XDSL.XDSLWriter(model, network_id='MyNetwork', num_samples='0', disc_samples='0', encoding='utf-8')[source]¶
Initialise a XDSL writer object to export pgmpy models to XDSL file format[1] used by GeNIe[2].
- Parameters:
model (pgmpy.models.DiscreteBayesianNetwork instance.) – The model to write to the file.
network_id (str (default: "MyNetwork")) – Name/id of the network
num_samples (int (default: 0)) – Number of samples used for continuous variables
disc_samples (int (default: 0)) – Number of samples used for discrete variables
encoding (str (optional, default='utf-8')) – Encoding for text data
Examples
>>> from pgmpy.readwrite import XDSLWriter >>> from pgmpy.utils import get_example_model >>> asia = get_example_model('asia') >>> writer = XDSLWriter(asia) >>> writer.write_xdsl('asia.xdsl')
Reference¶
[1] https://support.bayesfusion.com/docs/GeNIe/saving_xdslfileformat.html [2] https://www.bayesfusion.com/genie/
- get_cpds()[source]¶
Add the complete CPT element (with states and probabilities) to XDSL.
- Returns:
dict
- Return type:
dict of type {variable: table tag}
Examples
>>> writer = XMLBIFWriter(model) >>> writer.get_values() {'asia': <TabularCPD representing P(asia:2) at 0x1885817c830>, 'tub': <TabularCPD representing P(tub:2 | asia:2) at 0x1885a7e57c0>, 'smoke': <TabularCPD representing P(smoke:2) at 0x18858327950>, 'lung': <TabularCPD representing P(lung:2 | smoke:2) at 0x188583278f0>, 'bronc': <TabularCPD representing P(bronc:2 | smoke:2) at 0x18855e05610>, 'either': <TabularCPD representing P(either:2 | lung:2, tub:2) at 0x188582792e0>, 'xray': <TabularCPD representing P(xray:2 | either:2) at 0x1885a7e5910>, 'dysp': <TabularCPD representing P(dysp:2 | bronc:2, either:2) at 0x18858278b90>}
- get_variables()[source]¶
Add variables and their XML elements/representation to XDSL
- Returns:
dict
- Return type:
dict of type {variable: variable tags}
Examples
>>> writer = XMLBIFWriter(model) >>> writer.get_variables() {'asia': <Element 'cpt' at 0x000001DC6BFA1350>, 'tub': <Element 'cpt' at 0x000001DC6BFA35B0>, 'smoke': <Element 'cpt' at 0x000001DC6BFA3560>, 'lung': <Element 'cpt' at 0x000001DC6BFA12B0>, 'bronc': <Element 'cpt' at 0x000001DC6BFA1260>, 'either': <Element 'cpt' at 0x000001DC6BFA3510>, 'xray': <Element 'cpt' at 0x000001DC6BFA34C0>, 'dysp': <Element 'cpt' at 0x000001DC6BFA1210>}
- write_xdsl(filename=None)[source]¶
Write the xdsl data into the file.
- Parameters:
filename (Name (path) of the file.)
Examples
>>> from pgmpy.readwrite import XDSLWriter >>> from pgmpy.utils import get_example_model >>> model = get_example_model('asia') >>> writer = XDSLWriter(model) >>> writer.write_xdsl('asia.xdsl')