SMILearn Tutorial 5: Learning with the EM Algorithm (Static)

From DSL
Jump to: navigation, search

In this tutorial, we will shows how to learn the parameters of a Bayesian model (File:Net tut 5.xdsl) with the EM algorithm. The network structure looks as follows:

Net tut 5.png

We will use the following data set (ds_tut_5.txt), encoding a probabilistic version of the AND logical operator:

  A B C
  t t t
  t f f
  f t f
  f f f
  t t t
  t f t
  f t f
  f f t

First, we read the data set in:

  DSL_dataset ds;
  if (ds.ReadFile("ds_tut_5.txt") != DSL_OKAY) {
     cout << "Cannot read data file... exiting." << endl;
     exit(1);
  }

Next, we open the network:

  DSL_network net;
  if (net.ReadFile("net_tut_5.xdsl", DSL_XDSL_FORMAT) != DSL_OKAY) {
     cout << "Cannot read network... exiting." << endl;
     exit(1);
  }

Then, we associate the data set variables and their states to variables and states in the network:

  vector<DSL_datasetMatch> matches;
  string err;
  if (ds.MatchNetwork(net, matches, err) != DSL_OKAY) {
     cout << "Cannot match network... exiting." << endl;
     exit(1);
  }

What is left is to perform the parameter learning and save the results:

  DSL_em em;
  if (em.Learn(ds, net, matches) != DSL_OKAY) {
     cout << "Cannot learn parameters... exiting." << endl;
     exit(1);
  }
  net.WriteFile("res_tut_5.xdsl", DSL_XDSL_FORMAT);
Personal tools