private TableFactor marginalizeMessage ( TableFactor message , int [ ] relevant , MarginalizationMethod marginalize ) { TableFactor result = message ; for ( int i : message . neighborIndices ) { boolean contains = false ; for ( int j : relevant ) { if ( i == j ) { contains = true ; break ; } } if ( ! contains ) { switch ( marginalize ) { case SUM : result = result . sumOut ( i ) ; break ; case MAX : result = result . maxOut ( i ) ; break ; } } } return result ; }
This is a key step in message passing . When we are calculating a message we want to marginalize out all variables not relevant to the recipient of the message . This function does that .