UAI

class pgmpy.readwrite.UAI.UAIReader(path=None, string=None)[source]

Class for reading UAI file format from files or strings.

get_domain()[source]

Returns the dictionary of variables with keys as variable name and values as domain of the variables.

Returns

dict

Return type

dictionary containing variables and their domains

Examples

>>> from pgmpy.readwrite import UAIReader
>>> reader = UAIReader('TestUAI.uai')
>>> reader.get_domain()
{'var_0': '2', 'var_1': '2', 'var_2': '3'}
get_edges()[source]

Returns the edges of the network.

Returns

set

Return type

set containing the edges of the network

Examples

>>> from pgmpy.readwrite import UAIReader
>>> reader = UAIReader('TestUAI.uai')
>>> reader.get_edges()
{('var_0', 'var_1'), ('var_0', 'var_2'), ('var_1', 'var_2')}
get_grammar()[source]

Returns the grammar of the UAI file.

get_model()[source]

Returns an instance of Bayesian Model or Markov Model. Variables are in the pattern var_0, var_1, var_2 where var_0 is 0th index variable, var_1 is 1st index variable.

Returns

model

Return type

an instance of Bayesian or Markov Model.

Examples

>>> from pgmpy.readwrite import UAIReader
>>> reader = UAIReader('TestUAI.uai')
>>> reader.get_model()
get_network_type()[source]

Returns the type of network defined by the file.

Returns

string – String containing network type.

Return type

str

Examples

>>> from pgmpy.readwrite import UAIReader
>>> reader = UAIReader('TestUAI.uai')
>>> reader.get_network_type()
'MARKOV'
get_tables()[source]

Returns list of tuple of child variable and CPD in case of Bayesian and list of tuple of scope of variables and values in case of Markov.

Returns

list – list of tuples of scope of variables and values in case of Markov.

Return type

list of tuples of child variable and values in Bayesian

Examples

>>> from pgmpy.readwrite import UAIReader
>>> reader = UAIReader('TestUAI.uai')
>>> reader.get_tables()
[(['var_0', 'var_1'], ['4.000', '2.400', '1.000', '0.000']),
 (['var_0', 'var_1', 'var_2'],
  ['2.2500', '3.2500', '3.7500', '0.0000', '0.0000', '10.0000',
   '1.8750', '4.0000', '3.3330', '2.0000', '2.0000', '3.4000'])]
get_variables()[source]

Returns a list of variables. Each variable is represented by an index of list. For example if the no of variables are 4 then the list will be [var_0, var_1, var_2, var_3]

Returns

list

Return type

list of variables

Examples

>>> from pgmpy.readwrite import UAIReader
>>> reader = UAIReader('TestUAI.uai')
>>> reader.get_variables()
['var_0', 'var_1', 'var_2']
class pgmpy.readwrite.UAI.UAIWriter(model)[source]

Class for writing models in UAI.

get_domain()[source]

Adds domain of each variable to the network.

Examples

>>> from pgmpy.readwrite import UAIWriter
>>> writer = UAIWriter(model)
>>> writer.get_domain()
get_functions()[source]

Adds functions to the network.

Examples

>>> from pgmpy.readwrite import UAIWriter
>>> writer = UAIWriter(model)
>>> writer.get_functions()
get_nodes()[source]

Adds variables to the network.

Examples

>>> from pgmpy.readwrite import UAIWriter
>>> writer = UAIWriter(model)
>>> writer.get_nodes()
get_tables()[source]

Adds tables to the network.

Examples

>>> from pgmpy.readwrite import UAIWriter
>>> writer = UAIWriter(model)
>>> writer.get_tables()
write_uai(filename)[source]

Write the xml data into the file.

Parameters

filename (Name of the file.) –

Examples

>>> from pgmpy.readwrite import UAIWriter
>>> from pgmpy.utils import get_example_model
>>> model = get_example_model('asia')
>>> writer = UAIWriter(asia)
>>> writer.write_uai('asia.uai')