}
private void reComputeFunctionValueAndGradientHelper(double[] weightsForTheta){
MinRiskDADenseFeaturesSemiringParser gradientSemiringParser
= new MinRiskDADenseFeaturesSemiringParser(temperature);
for(int sentID=0; sentID < numSentence; sentID ++){
//System.out.println("#Process sentence " + sent_id);
FeatureForest fForest = hgFactory.nextHG(sentID);
fForest.setFeatureWeights(weightsForTheta);
fForest.setScale(scalingFactor);
/** Based on a model and a test hypergraph (which provides the topology and feature/risk annotation),
* compute the gradient.
**/
//@todo: we should check if hg_test is a feature forest or not
gradientSemiringParser.setHyperGraph(fForest);
//== compute gradient and function value
HashMap<Integer, Double> gradients = gradientSemiringParser.computeGradientForTheta();
double gradientForScalingFactor = 0;
if(shouldComputeGradientForScalingFactor)
gradientForScalingFactor = computeGradientForScalingFactor(gradients, weightsForTheta, scalingFactor);
double funcVal = gradientSemiringParser.getFuncVal();
double risk = gradientSemiringParser.getRisk();
double entropy = gradientSemiringParser.getEntropy();
//== accumulate gradient and function value
accumulateGradient(gradients, gradientForScalingFactor, weightsForTheta, funcVal, risk, entropy);