Wednesday 12 August 2015

UAI Reader And Wrirter

After mid term, I worked on UAI reader and writer module.Now, it has been successfully merged into the main repository.

UAI Format Brief Description

It uses the simple text file format specified below to describe problem instances
Link to the format :  UAI

A file in the UAI format consists of the following two parts, in that order:
  1. Preamble
  2. Function 
Preamble: It starts with a text denoting the type of the network.This is followed by a line containing the number of variables. The next line specifies each variable's domain size, one at a time, separated by whitespace.The fourth line contains only one integer, denoting the number of functions in the problem (conditional probability tables for Bayesian networks, general factors for Markov networks). Then, one function per line, the scope of each function is given as follows: The first integer in each line specifies the size of the function's scope, followed by the actual indexes of the variables in the scope. The order of this list is not restricted, except when specifying a conditional probability table (CPT) in a Bayesian network, where the child variable has to come last. Also note that variables are indexed starting with 0. 

Example of Preamble

MARKOV
3
2 2 3
2
2 0 1
3 0 1 2
 In the above example the model is MARKOV and no of variables are 3, and domain size of the variables are 2 2 3 respectively.

So for reading the preamble,  we have used pyparsing module. And to get the no of variables and their domain sizes we have declared method get_variables and get_domain which will return the list of variables and the dictionary with key as variable name and value as their domain size.

For example, for the above preamble the method get_variables will return [var_0, var_1, var_2]
and the method get_domain will return
{var_0: 2, var_1: 2, var_2: 3}

Function: In this section each function is specified by giving its full table (i.e, specifying the function value for each tuple). The order of the functions is identical to the one in which they were introduced in the preamble.


For each function table, first the number of entries is given (this should be equal to the product of the domain sizes of the variables in the scope). Then, one by one, separated by whitespace, the values for each assignment to the variables in the function's scope are enumerated. Tuples are implicitly assumed in ascending order, with the last variable in the scope as the 'least significant'.

Example of Function
2
0.436 0.564

4
0.128 0.872
0.920 0.080

6
0.210 0.333 0.457
0.811 0.000 0.189 

No comments:

Post a Comment