// return changed hg
public HyperGraph decoding(HyperGraph hg, int sentenceID, BufferedWriter out) {
//=== step-1: run inside-outside
//note, inside and outside will use the transition_cost of each hyperedge, this cost is already linearly interpolated
TrivialInsideOutside pInsideOutside = new TrivialInsideOutside();
pInsideOutside.runInsideOutside(hg, 0, 1, insideOutsideScalingFactor);//ADD_MODE=0=sum; LOG_SEMIRING=1;
//=== initialize baseline table
//TODO:????????????????????
((EdgeTblBasedBaselineFF)featFunctions.get(0)).collectTransitionLogPs(hg);
//=== step-2: model extraction based on the definition of Q
for(Map.Entry<VariationalNgramApproximator, FeatureTemplateBasedFF> entry : approximatorMap.entrySet()){
VariationalNgramApproximator approximator = entry.getKey();
FeatureTemplateBasedFF featureFunction = entry.getValue();
HashMap<String, Double> model = approximator.estimateModel(hg, pInsideOutside);
featureFunction.setModel(model);
}
//clean up
pInsideOutside.clearState();
//=== step-3: rank the HG using the baseline and variational feature
this.ranker.rankHG(hg);
//=== step-4: kbest extraction from the reranked HG: remember to add the new feature function into the model list