public void decode ( FgInferencer infLatPred , UFgExample ex ) { FactorGraph fgLatPred = ex . getFactorGraph ( ) ; mbrVarConfig = new VarConfig ( ) ; margs = new ArrayList < VarTensor > ( ) ; varMargMap = new HashMap < Var , Double > ( ) ; // Get the MBR configuration of all the latent and predicted // variables. if ( prm . loss == Loss . L1 || prm . loss == Loss . MSE ) { for ( int varId = 0 ; varId < fgLatPred . getNumVars ( ) ; varId ++ ) { Var var = fgLatPred . getVar ( varId ) ; VarTensor marg = infLatPred . getMarginalsForVarId ( varId ) ; margs . add ( marg ) ; int argmaxState = marg . getArgmaxConfigId ( ) ; mbrVarConfig . put ( var , argmaxState ) ; varMargMap . put ( var , marg . getValue ( argmaxState ) ) ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Variable marginal: " + marg ) ; } } } else { throw new RuntimeException ( "Loss type not implemented: " + prm . loss ) ; } }
Computes the MBR variable configuration from the marginals cached in the inferencer which is assumed to have already been run . The outputs are stored on the class and can be queried after this call to decode .