private void forwardSendMessage ( int edge , int iter ) { // Update the residual double oldResidual = residuals [ edge ] ; residuals [ edge ] = smartResidual ( msgs [ edge ] , newMsgs [ edge ] , edge ) ; if ( oldResidual > prm . convergenceThreshold && residuals [ edge ] <= prm . convergenceThreshold ) { // This message has (newly) converged. numConverged ++ ; } if ( oldResidual <= prm . convergenceThreshold && residuals [ edge ] > prm . convergenceThreshold ) { // This message was marked as converged, but is no longer converged. numConverged -- ; } // Check for oscillation. Did the argmax change? if ( log . isTraceEnabled ( ) && iter > 0 ) { if ( msgs [ edge ] . getArgmaxConfigId ( ) != newMsgs [ edge ] . getArgmaxConfigId ( ) ) { oscillationCount . incrementAndGet ( ) ; } sendCount . incrementAndGet ( ) ; log . trace ( "Residual: {} {}" , fg . edgeToString ( edge ) , residuals [ edge ] ) ; } // Update the cached belief. int child = bg . childE ( edge ) ; if ( ! bg . isT1T2 ( edge ) && bg . numNbsT1 ( child ) >= prm . minVarNbsForCache ) { varBeliefs [ child ] . elemDivBP ( msgs [ edge ] ) ; varBeliefs [ child ] . elemMultiply ( newMsgs [ edge ] ) ; assert ! varBeliefs [ child ] . containsBadValues ( ) : "varBeliefs[child] = " + varBeliefs [ child ] ; } else if ( bg . isT1T2 ( edge ) && bg . numNbsT2 ( child ) >= prm . minFacNbsForCache ) { Factor f = bg . t2E ( edge ) ; if ( ! ( f instanceof GlobalFactor ) ) { facBeliefs [ child ] . divBP ( msgs [ edge ] ) ; facBeliefs [ child ] . prod ( newMsgs [ edge ] ) ; assert ! facBeliefs [ child ] . containsBadValues ( ) : "facBeliefs[child] = " + facBeliefs [ child ] ; } } // Send message: Just swap the pointers to the current message and the new message, so // that we don't have to create a new factor object. VarTensor oldMessage = msgs [ edge ] ; msgs [ edge ] = newMsgs [ edge ] ; newMsgs [ edge ] = oldMessage ; assert ! msgs [ edge ] . containsBadValues ( ) : "msgs[edge] = " + msgs [ edge ] ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Message sent: {} {}" , fg . edgeToString ( edge ) , msgs [ edge ] ) ; } }
Sends the message that is currently pending for this edge . This just copies the message in the pending slot to the message slot for this edge .