Adopted contributions by Christian.
[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 "../factorgraph.h"
23 #include <iostream>
24 #include <cstdlib>
25
26 using namespace dai;
27 using namespace std;
28
29
30 int main( int argc, char *argv[] ) {
31 if( argc != 2 ) {
32 cout << "Usage: " << argv[0] << " <in.fg>" << endl << endl;
33 cout << "Reports some characteristics of the .fg network." << endl;
34 return 1;
35 } else {
36 // Read factorgraph
37 FactorGraph fg;
38 char *infile = argv[1];
39
40 if( fg.ReadFromFile( infile ) ) {
41 cerr << "Error reading file " << infile << endl;
42 return 2;
43 } else {
44 cout << "Number of variables: " << fg.nrVars() << endl;
45 cout << "Number of factors: " << fg.nrFactors() << endl;
46 cout << "Connected: " << fg.isConnected() << 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(fg.var(i));
54 size_t Ds = fg.Delta(fg.var(i)).stateSpace();
55 if( Ds > max_Delta_size )
56 max_Delta_size = Ds;
57 cavsum_lcbp += di.stateSpace();
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 }
69