5 #include<dai/factorgraph.h>
6 #include<dai/evidence.h>
12 void usage(const string
& msg
) {
14 cerr
<< "Usage:" << endl
;
15 cerr
<< " testem factorgraph.fg evidence.tab emconfig.em" << endl
;
19 int main(int argc
, char** argv
) {
21 usage("Incorrect number of arguments.");
25 ifstream
fgstream(argv
[1]);
29 infprops
.Set("verbose", (size_t)1);
30 infprops
.Set("updates", string("HUGIN"));
31 InfAlg
* inf
= newInfAlg("JTREE", fg
, infprops
);
35 ifstream
estream(argv
[2]);
36 e
.addEvidenceTabFile(estream
, fg
);
38 cout
<< "Number of samples: " << e
.nrSamples() << endl
;
39 Evidence::iterator ps
= e
.begin();
40 for (; ps
!= e
.end(); ps
++) {
41 cout
<< "Sample " << ps
->first
<< " has "
42 << ps
->second
.observations().size() << " observations." << endl
;
45 ifstream
emstream(argv
[3]);
46 EMAlg
em(e
, *inf
, emstream
);
48 while(!em
.hasSatisfiedTermConditions()) {
49 Real l
= em
.iterate();
50 cout
<< "Iteration " << em
.getCurrentIters() << " likelihood: " << l
<<endl
;
54 << "Inferred Factor Graph:" << endl
55 << "######################" << endl