Fixed previous partial commit which left everything broken
[libdai.git] / utils / fginfo.cpp
1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Radboud University Nijmegen, The Netherlands
3
4 This file is part of libDAI.
5
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.
10
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.
15
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
19 */
20
21
22 #include <iostream>
23 #include <cstdlib>
24 #include <dai/factorgraph.h>
25
26
27 using namespace dai;
28 using namespace std;
29
30
31 int main( int argc, char *argv[] ) {
32 if( argc != 2 ) {
33 cout << "Usage: " << argv[0] << " <in.fg>" << endl << endl;
34 cout << "Reports some characteristics of the .fg network." << endl;
35 return 1;
36 } else {
37 // Read factorgraph
38 FactorGraph fg;
39 char *infile = argv[1];
40
41 fg.ReadFromFile( infile );
42 cout << "Number of variables: " << fg.nrVars() << endl;
43 cout << "Number of factors: " << fg.nrFactors() << endl;
44 cout << "Connected: " << fg.isConnected() << endl;
45 cout << "Binary variables? " << fg.isBinary() << endl;
46 cout << "Pairwise interactions? " << fg.isPairwise() << endl;
47 // cout << "Treewidth: " << endl;
48
49 double cavsum_lcbp = 0.0;
50 double cavsum_lcbp2 = 0.0;
51 size_t max_Delta_size = 0;
52 for( size_t i = 0; i < fg.nrVars(); i++ ) {
53 VarSet di = fg.delta(i);
54 size_t Ds = fg.Delta(i).states();
55 if( Ds > max_Delta_size )
56 max_Delta_size = Ds;
57 cavsum_lcbp += di.states();
58 for( VarSet::const_iterator j = di.begin(); j != di.end(); j++ )
59 cavsum_lcbp2 += j->states();
60 }
61 cout << "Maximum pancake has " << max_Delta_size << " states" << endl;
62 cout << "LCBP with full cavities needs " << cavsum_lcbp << " BP runs" << endl;
63 cout << "LCBP with only pairinteractions needs " << cavsum_lcbp2 << " BP runs" << endl;
64
65 return 0;
66 }
67 }
68