Implementing TRWBP
[libdai.git] / src / fbp.cpp
index 0e67cc5..893388e 100644 (file)
@@ -73,16 +73,14 @@ void FBP::calcNewMessage( size_t i, size_t _I ) {
                         prod_j += message( j, J.iter );
                     else
                         prod_j *= message( j, J.iter );
+                } else {
+                    // FBP: multiply by m_Ij^(1-1/c_I)
+                    if( props.logdomain )
+                        prod_j += message( j, J.iter )*(1-1/scale);
+                    else
+                        prod_j *= message( j, J.iter )^(1-1/scale);
                 }
 
-
-            size_t _I = j.dual;
-            // FBP: now multiply by m_Ij^(1-1/c_I)
-            if(props.logdomain)
-                prod_j += message( j, _I)*(1-1/scale);
-            else
-                prod_j *= message( j, _I)^(1-1/scale);
-
             // multiply prod with prod_j
             if( !DAI_FBP_FAST ) {
                 /* UNOPTIMIZED (SIMPLE TO READ, BUT SLOW) VERSION */
@@ -168,16 +166,14 @@ void FBP::calcBeliefF( size_t I, Prob &p ) const {
                     prod_j += newMessage( j, J.iter );
                 else
                     prod_j *= newMessage( j, J.iter );
+            } else {
+                // FBP: multiply by m_Ij^(1-1/c_I)
+                if( props.logdomain )
+                    prod_j += newMessage( j, J.iter)*(1-1/scale);
+                else
+                    prod_j *= newMessage( j, J.iter)^(1-1/scale);
             }
 
-        size_t _I = j.dual;
-
-        // FBP: now multiply by m_Ij^(1-1/c_I)
-        if( props.logdomain )
-            prod_j += newMessage( j, _I)*(1-1/scale);
-        else
-            prod_j *= newMessage( j, _I)^(1-1/scale);
-
         // multiply prod with prod_j
         if( !DAI_FBP_FAST ) {
             /* UNOPTIMIZED (SIMPLE TO READ, BUT SLOW) VERSION */