Step-by-step guide to use EM?

The engine.
Post Reply
alberto.tonda
Posts: 1
Joined: Tue Feb 18, 2014 3:00 pm

Step-by-step guide to use EM?

Post by alberto.tonda »

Dear Genie/SMILE community,

I have successfully used some tools from the smilearn library to get a complete Bayesian network (structure + parameters) from a dataset. Right now I am trying to use EM, and I am facing several problems, probably arising from a combination of my own inexperience :-D and missing/outdated parts in the tutorials.

My objective is to create a network, add the nodes, add some arcs, then learn the parameters from a dataset with no missing values. There are no hidden nodes.

Right now, my code resembles this:

Code: Select all

                // Bayesian Network class from SMILE library
                DSL_network network;

                // dataset from SMILE library
                DSL_dataset dataset;
                string errOut;

                if( dataset.ReadFile(fileName.c_str(), NULL, &errOut) != 0 )
                {
                        cerr << "Error while reading file \"" << fileName << "\": " << errOut << endl;
                        exit(0);
                }

               // here I add the nodes, iterating over the variable names in the dataset, using network.AddNode(DSL_TABLE, nodeName)
               // ...

               // then, I add some arcs, using network.AddArc(handler1, handler2), finding the handlers with network.FindNode(nodeName)
               // ...

              // finally, I launch EM
              DSL_em em;
              vector<DSL_datasetMatch> matches;
              string errMsg;

              em.Learn(dataset, network, matches);

Afterwards, when I look at the tables inside each node, the probability values look uninitialized (with weird values such as 4.94066e-324).

What am I doing wrong? Thank you in advance for your help!
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Step-by-step guide to use EM?

Post by shooltz[BayesFusion] »

You need to associate nodes in your network with data columns in the dataset. If the node/column ids are identical, you can use DSL_dataset::MatchNetwork. Otherwise you'll need to fill the 'matches' vector using your own code and knowledge specific to network/data.

Code: Select all

vector<DSL_datasetMatch> matches;
string errMsg;
dataset.MatchNetwork(net, matches, errMsg);
int result = em.Learn(dataset, network, matches);
Post Reply