Getting CPTs from Text Files

Netica

Getting CPTs from Text Files

If you want Netica to learn the CPTs based on data records in text files, see the chapter on learning instead; here we obtain actual probability numbers directly from text files.

There are a few ways to "import" entire CPTs to the network from files:

1. Cut & Paste:   If the table is in tab-delimited form, with each row corresponding to the various states of the child node, you can just paste it into the table dialog box for the node.  First, read the table with a text editing program (e.g. word processor, or choose File Open as Text).  Select the entire table and choose Edit Copy.

Then open the table editor for the child node (Table View/Edit), and select the upper left cell (by right-clicking it, or by left-clicking and dragging a tiny distance within it).  The cell should turn black.  Finally choose Edit Paste, and the entire table will be filled.

Your table in the text file must use the same order of parents as in the table dialog box.  If they aren't the same, you can adjust the columns beforehand just by clicking and dragging in its heading.

You can also copy and paste in a similar way from a spreadsheet program, such as Excel.

2.  Make a simulated "case file":  with 1 row for each entry of the CPT table (i.e. the Cartesian product of the parents and the child node itself).  That means that if the child node has n states, there will be n times as many rows in your simulated case file as there are rows in the CPT table.

The first column of the case file should be NumCases, and in that column you place the CPT probabilities.

Then choose Cases Learn Incorp Case File, and it will read the probabilities in as the frequency for each case.  You will need to Table Harden with a degree of 1 afterwards.  Or, you can multiply all the probabilities in the case file by some large number (the same number for one), so it is as if you are presenting Netica with a set of cases whose probability distribution matches the CPT numbers.

3.  Use a .dne file:   Save the Bayes net as a .dne file (from the Save As dialog box, choose dne from the menu in the box, or make the file name end with .dne).  Then open the .dne file with a text editor.  It will be quite readable, and you should easily be able to find the table for the node in question.  (if there is no table there, you may want to create a dummy table in Netica beforehand with Table Uniform).  Simply copy the whole table as text, and then paste to replace the table in the .dne file.  The table in your text file must be comma-delimited, with each row corresponding to the states of the child node, and the rows in odometer order corresponding to the same order of parent nodes as is shown in the .dne file (you can re-order the parents as described above).   Don't worry about the comments that were on each line of the .dne file (i.e., the parts starting with "//"); they aren't needed.

4. Write a Program:   If you want it to be an automated process, you can write a program that reads the text file, and then does calls to Netica API  to fill the CPT Tables.