+++ /dev/null
-/* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
- Radboud University Nijmegen, The Netherlands /
- Max Planck Institute for Biological Cybernetics, Germany
-
- This file is part of libDAI.
-
- libDAI is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- libDAI is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with libDAI; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-#include <iostream>
-#include <dai/alldai.h>
-
-
-using namespace dai;
-using namespace std;
-
-
-int main( int argc, char *argv[] ) {
- if ( argc != 2 ) {
- cout << "Usage: " << argv[0] << " <filename.fg>" << endl << endl;
- cout << "Reads factor graph <filename.fg> and runs" << endl;
- cout << "Belief Propagation and JunctionTree on it." << endl << endl;
- return 1;
- } else {
- FactorGraph fg;
- fg.ReadFromFile(argv[1]);
-
- size_t maxiter = 10000;
- double tol = 1e-9;
- size_t verb = 1;
-
- PropertySet opts;
- opts.Set("maxiter",maxiter);
- opts.Set("tol",tol);
- opts.Set("verbose",verb);
-
- JTree jt( fg, opts("updates",string("HUGIN")) );
- jt.init();
- jt.run();
-
- BP bp(fg, opts("updates",string("SEQFIX"))("logdomain",false));
- bp.init();
- bp.run();
-
- cout << "Exact single node marginals:" << endl;
- for( size_t i = 0; i < fg.nrVars(); i++ )
- cout << jt.belief(fg.var(i)) << endl;
-
- cout << "Approximate (loopy belief propagation) single node marginals:" << endl;
- for( size_t i = 0; i < fg.nrVars(); i++ )
- cout << bp.belief(fg.var(i)) << endl;
-
- cout << "Exact factor marginals:" << endl;
- for( size_t I = 0; I < fg.nrFactors(); I++ )
- cout << jt.belief(fg.factor(I).vars()) << endl;
-
- cout << "Approximate (loopy belief propagation) factor marginals:" << endl;
- for( size_t I = 0; I < fg.nrFactors(); I++ )
- cout << bp.belief(fg.factor(I).vars()) << "=" << bp.beliefF(I) << endl;
-
- cout << "Exact log partition sum: " << jt.logZ() << endl;
- cout << "Approximate (loopy belief propagation) log partition sum: " << bp.logZ() << endl;
- }
-
- return 0;
-}
--- /dev/null
+/* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
+ Radboud University Nijmegen, The Netherlands /
+ Max Planck Institute for Biological Cybernetics, Germany
+
+ This file is part of libDAI.
+
+ libDAI is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libDAI is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libDAI; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include <iostream>
+#include <dai/alldai.h>
+
+
+using namespace dai;
+using namespace std;
+
+
+int main( int argc, char *argv[] ) {
+ if ( argc != 2 ) {
+ cout << "Usage: " << argv[0] << " <filename.fg>" << endl << endl;
+ cout << "Reads factor graph <filename.fg> and runs" << endl;
+ cout << "Belief Propagation and JunctionTree on it." << endl << endl;
+ return 1;
+ } else {
+ FactorGraph fg;
+ fg.ReadFromFile(argv[1]);
+
+ size_t maxiter = 10000;
+ double tol = 1e-9;
+ size_t verb = 1;
+
+ PropertySet opts;
+ opts.Set("maxiter",maxiter);
+ opts.Set("tol",tol);
+ opts.Set("verbose",verb);
+
+ JTree jt( fg, opts("updates",string("HUGIN")) );
+ jt.init();
+ jt.run();
+
+ BP bp(fg, opts("updates",string("SEQFIX"))("logdomain",false));
+ bp.init();
+ bp.run();
+
+ cout << "Exact single node marginals:" << endl;
+ for( size_t i = 0; i < fg.nrVars(); i++ )
+ cout << jt.belief(fg.var(i)) << endl;
+
+ cout << "Approximate (loopy belief propagation) single node marginals:" << endl;
+ for( size_t i = 0; i < fg.nrVars(); i++ )
+ cout << bp.belief(fg.var(i)) << endl;
+
+ cout << "Exact factor marginals:" << endl;
+ for( size_t I = 0; I < fg.nrFactors(); I++ )
+ cout << jt.belief(fg.factor(I).vars()) << endl;
+
+ cout << "Approximate (loopy belief propagation) factor marginals:" << endl;
+ for( size_t I = 0; I < fg.nrFactors(); I++ )
+ cout << bp.belief(fg.factor(I).vars()) << "=" << bp.beliefF(I) << endl;
+
+ cout << "Exact log partition sum: " << jt.logZ() << endl;
+ cout << "Approximate (loopy belief propagation) log partition sum: " << bp.logZ() << endl;
+ }
+
+ return 0;
+}
--- /dev/null
+#include <dai/bipgraph.h>
+
+using namespace std;
+using namespace dai;
+
+int main() {
+ vector<BipartiteGraph::Edge> edges;
+ edges.reserve( 5 );
+ edges.push_back( BipartiteGraph::Edge(0, 0) );
+ edges.push_back( BipartiteGraph::Edge(1, 0) );
+ edges.push_back( BipartiteGraph::Edge(2, 0) );
+ edges.push_back( BipartiteGraph::Edge(1, 1) );
+ edges.push_back( BipartiteGraph::Edge(2, 1) );
+ BipartiteGraph G( 3, 2, edges.begin(), edges.end() );
+
+ cout << "G has " << G.nr1() << " nodes of type 1, " << G.nr2() << " nodes of type 2 and " << G.nrEdges() << " edges." << endl << endl;
+
+ for( size_t n1 = 0; n1 < G.nr1(); n1++ ) {
+ cout << "Node " << n1 << " of type 1 has " << G.nb1(n1).size() << " neighbors:" << endl;
+ foreach( const BipartiteGraph::Neighbor &n2, G.nb1(n1) ) {
+ size_t _n2 = n2.iter;
+ size_t _n1 = n2.dual;
+ cout << " the " << n2.iter << "'th neighbor is node " << n2 << " of type 2" << endl;
+
+ // The _n2'th neighbor of n1 is n2:
+ assert( G.nb1(n1)[_n2] == n2 );
+ // The _n1'th neighbor of n2 is n1:
+ assert( G.nb2(n2)[_n1] == n1 );
+ // n2 can be used as an abbreviation of n2.node:
+ assert( static_cast<size_t>(n2) == n2.node );
+ }
+ cout << endl;
+ }
+}
--- /dev/null
+G has 3 nodes of type 1, 2 nodes of type 2 and 5 edges.
+
+Node 0 of type 1 has 1 neighbors:
+ the 0'th neighbor is node 0 of type 2
+
+Node 1 of type 1 has 2 neighbors:
+ the 0'th neighbor is node 0 of type 2
+ the 1'th neighbor is node 1 of type 2
+
+Node 2 of type 1 has 2 neighbors:
+ the 0'th neighbor is node 0 of type 2
+ the 1'th neighbor is node 1 of type 2
+