parse_bif#

causalbase.io.parse_bif(text, source='<string>')[source]#

Parse the text of a BIF file into a DiscreteBN.

Parameters:
textstr

The contents of a .bif file.

sourcestr, default=”<string>”

Where the text comes from, for the error messages.

Returns:
DiscreteBN

The network, its variables in the order the file declares them.

Raises:
ValueError

If the text is not BIF, a table names an unknown variable or state, has the wrong size or leaves a configuration out, or a row does not sum to 1.

Examples

>>> from causalbase.io import parse_bif
>>> bn = parse_bif('''
... variable rain { type discrete [ 2 ] { yes, no }; }
... variable wet { type discrete [ 2 ] { yes, no }; }
... probability ( rain ) { table 0.2, 0.8; }
... probability ( wet | rain ) { (yes) 0.9, 0.1; (no) 0.1, 0.9; }
... ''')
>>> bn.names, bn.dag.edges()
(['rain', 'wet'], [(0, 1)])