53adcfc2052d36697772e4388f79860b9b418351
1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Radboud University Nijmegen, The Netherlands
4 This file is part of libDAI.
6 libDAI is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libDAI is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libDAI; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <dai/alldai.h>
30 int main( int argc
, char *argv
[] ) {
32 cout
<< "Usage: " << argv
[0] << " <filename.fg>" << endl
<< endl
;
33 cout
<< "Reads factor graph <filename.fg> and runs" << endl
;
34 cout
<< "Belief Propagation and JunctionTree on it." << endl
<< endl
;
39 if( fg
.ReadFromFile(argv
[1]) ) {
40 cout
<< "Error reading " << argv
[1] << endl
;
43 size_t maxiter
= 1000;
48 opts
.Set("maxiter",maxiter
);
50 opts
.Set("verbose",verb
);
52 JTree
jt( fg
, opts("updates",string("HUGIN")) );
56 cout
<< "Exact single node marginals:" << endl
;
57 for( size_t i
= 0; i
< fg
.nrVars(); i
++ )
58 cout
<< jt
.belief(fg
.var(i
)) << endl
;
60 BP
bp(fg
, opts("updates",string("SEQMAX")));
64 cout
<< "Approximate (loopy belief propagation) single node marginals:" << endl
;
65 for( size_t i
= 0; i
< fg
.nrVars(); i
++ )
66 cout
<< bp
.belief(fg
.var(i
)) << endl
;