static public void computeNormalizedProbs(List<Double> nbestLogProbs,double scalingFactor){
  double normalizationConstant=Double.NEGATIVE_INFINITY;
  for (  double logp : nbestLogProbs) {
    normalizationConstant=addInLogSemiring(normalizationConstant,logp * scalingFactor,0);
  }
  double tSum=0;
  for (int i=0; i < nbestLogProbs.size(); i++) {
    double normalizedProb=Math.exp(nbestLogProbs.get(i) * scalingFactor - normalizationConstant);
    tSum+=normalizedProb;
    nbestLogProbs.set(i,normalizedProb);
    if (Double.isNaN(normalizedProb)) {
      throw new RuntimeException("prob is NaN, must be wrong\nnbest_logps.get(i): " + nbestLogProbs.get(i) + "; scaling_factor: "+ scalingFactor+ "; normalization_constant:"+ normalizationConstant);
    }
  }
  if (Math.abs(tSum - 1.0) > 1e-4) {
    throw new RuntimeException("probabilities not sum to one, must be wrong");
  }
}

static public void computeNormalizedProbs ( List < Double > nbestLogProbs , double scalingFactor ) { double normalizationConstant = Double . NEGATIVE_INFINITY ; for ( double logp : nbestLogProbs ) { normalizationConstant = addInLogSemiring ( normalizationConstant , logp * scalingFactor , 0 ) ; } double tSum = 0 ; for ( int i = 0 ; i < nbestLogProbs . size ( ) ; i ++ ) { double normalizedProb = Math . exp ( nbestLogProbs . get ( i ) * scalingFactor - normalizationConstant ) ; tSum += normalizedProb ; nbestLogProbs . set ( i , normalizedProb ) ; if ( Double . isNaN ( normalizedProb ) ) { throw new RuntimeException ( "prob is NaN, must be wrong\nnbest_logps.get(i): " + nbestLogProbs . get ( i ) + "; scaling_factor: " + scalingFactor + "; normalization_constant:" + normalizationConstant ) ; } } if ( Math . abs ( tSum - 1.0 ) > 1e-4 ) { throw new RuntimeException ( "probabilities not sum to one, must be wrong" ) ; } }
based on a list of log - probabilities in nbestlogprobs , obtain a normalized distribution , and put the normalized probability ( real value in [ 0 , 1 ] ) into nbestlogprobs
