Initial commit of libDAI-0.2.1
[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 <stdlib.h>
25
26 using namespace std;
27
28
29 int main( int argc, char *argv[] ) {
30 if( argc != 2 ) {
31 cout << "Usage: " << argv[0] << " <in.fg>" << endl << endl;
32 cout << "Reports some characteristics of the .fg network." << endl;
33 return 1;
34 } else {
35 // Read factorgraph
36 FactorGraph fg;
37 char *infile = argv[1];
38
39 if( fg.ReadFromFile( infile ) ) {
40 cerr << "Error reading file " << infile << endl;
41 return 2;
42 } else {
43 cout << "Number of variables: " << fg.nrVars() << endl;
44 cout << "Number of factors: " << fg.nrFactors() << endl;
45 cout << "Connected: " << fg.isConnected() << endl;
46 // cout << "Treewidth: " << endl;
47
48 double cavsum_lcbp = 0.0;
49 double cavsum_lcbp2 = 0.0;
50 size_t max_Delta_size = 0;
51 for( size_t i = 0; i < fg.nrVars(); i++ ) {
52 VarSet di = fg.delta(fg.var(i));
53 size_t Ds = fg.Delta(fg.var(i)).stateSpace();
54 if( Ds > max_Delta_size )
55 max_Delta_size = Ds;
56 cavsum_lcbp += di.stateSpace();
57 for( VarSet::const_iterator j = di.begin(); j != di.end(); j++ )
58 cavsum_lcbp2 += j->states();
59 }
60 cout << "Maximum pancake has " << max_Delta_size << " states" << endl;
61 cout << "LCBP with full cavities needs " << cavsum_lcbp << " BP runs" << endl;
62 cout << "LCBP with only pairinteractions needs " << cavsum_lcbp2 << " BP runs" << endl;
63
64 return 0;
65 }
66 }
67 }
68