Fixed a bug in TreeEP related to disconnected factor graphs
authorJoris Mooij <joris.mooij@tuebingen.mpg.de>
Tue, 20 Apr 2010 13:23:24 +0000 (15:23 +0200)
committerJoris Mooij <joris.mooij@tuebingen.mpg.de>
Tue, 20 Apr 2010 13:23:24 +0000 (15:23 +0200)
src/treeep.cpp

index 238df1b..06703c3 100644 (file)
@@ -75,11 +75,13 @@ TreeEP::TreeEP( const FactorGraph &fg, const PropertySet &opts ) : JTree(fg, opt
             // effective interaction strength between pairs of nodes
 
             WeightedGraph<Real> wg;
-            for( size_t i = 0; i < fg.nrVars(); ++i ) {
+            // in order to get a connected weighted graph, we start
+            // by connecting every variable to the zero'th variable with weight 0
+            for( size_t i = 1; i < fg.nrVars(); i++ )
+                wg[UEdge(i,0)] = 0.0;
+            for( size_t i = 0; i < fg.nrVars(); i++ ) {
                 Var v_i = fg.var(i);
                 VarSet di = fg.delta(i);
-                if( i )
-                    wg[UEdge(i,0)] = 0.0;
                 for( VarSet::const_iterator cit_j = di.begin(); cit_j != di.end(); cit_j++ )
                     if( v_i < *cit_j ) {
                         VarSet ij(v_i,*cit_j);