1 /* This file is part of libDAI - http://www.libdai.org/
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
7 * Copyright (C) 2009 Charles Vaske [cvaske at soe dot ucsc dot edu]
8 * Copyright (C) 2009 University of California Santa Cruz
16 #include <dai/factorgraph.h>
17 #include <dai/evidence.h>
18 #include <dai/alldai.h>
25 void usage( const string
&msg
) {
27 cerr
<< "Usage:" << endl
;
28 cerr
<< " testem factorgraph.fg evidence.tab emconfig.em" << endl
;
33 int main( int argc
, char** argv
) {
35 usage("Incorrect number of arguments.");
38 fg
.ReadFromFile( argv
[1] );
41 infprops
.Set( "verbose", (size_t)1 );
42 infprops
.Set( "updates", string("HUGIN") );
43 InfAlg
* inf
= newInfAlg( "JTREE", fg
, infprops
);
47 ifstream
estream( argv
[2] );
48 e
.addEvidenceTabFile( estream
, fg
);
50 cout
<< "Number of samples: " << e
.nrSamples() << endl
;
51 for( Evidence::iterator ps
= e
.begin(); ps
!= e
.end(); ps
++ )
52 cout
<< "Sample #" << (ps
- e
.begin()) << " has " << ps
->observations().size() << " observations." << endl
;
54 ifstream
emstream( argv
[3] );
55 EMAlg
em(e
, *inf
, emstream
);
57 while( !em
.hasSatisfiedTermConditions() ) {
58 Real l
= em
.iterate();
59 cout
<< "Iteration " << em
.getCurrentIters() << " likelihood: " << l
<<endl
;
62 cout
<< endl
<< "Inferred Factor Graph:" << endl
<< "######################" << endl
;