Program: 52692
Project: 52692
Buggy source:
/** 
 * Calculates the best path using Viterbi decoding.
 * @param sentence sentece with ambiguous wrods.
 * @param useAveragedWeights if true, average weights are used for scoring, else, normal weightsare used.
 * @return best parse sequence and its score.
 */
ParseResult bestParse(SentenceData sentence,boolean useAveragedWeights){
  sentence.allWordAnalyses.add(WordData.SENTENCE_END);
  IntValueMap<StateId> stateIds=new IntValueMap<>();
  UIntMap<State> bestPath=new UIntMap<>();
  bestPath.put(0,new State(-1,0,null));
  stateIds.put(new StateId("String_Node_Str","String_Node_Str"),0);
  int bestStateNum=0;
  float bestScore=-100000;
  int n=0;
  for (  WordData word : sentence.allWordAnalyses) {
    IntValueMap<StateId> nextStates=new IntValueMap<>();
    List<String> allAnalyses=Lists.newArrayList(word.allParses);
    bestScore=-100000;
    for (    String analysis : allAnalyses) {
      for (      StateId id : stateIds) {
        int stateNum=stateIds.get(id);
        State state=bestPath.get(stateNum);
        List<String> trigram=Lists.newArrayList(id.first,id.second,analysis);
        IntValueMap<String> features=new IntValueMap<>();
        extractTrigramFeatures(trigram,features);
        float trigramScore=0;
        for (        String key : features) {
          if (useAveragedWeights) {
            trigramScore+=averagedWeights.weight(key) * features.get(key);
          }
 else {
            trigramScore+=weights.weight(key) * features.get(key);
          }
        }
        float newScore=trigramScore + state.score;
        StateId newStateId=new StateId(id.second,analysis);
        if (!nextStates.contains(newStateId)) {
          nextStates.put(newStateId,++n);
        }
        int nextStateNum=nextStates.get(newStateId);
        if (bestPath.containsKey(nextStateNum)) {
          State s=bestPath.get(nextStateNum);
          if (newScore > s.score) {
            bestPath.put(nextStateNum,new State(stateNum,newScore,analysis));
          }
        }
 else {
          bestPath.put(nextStateNum,new State(stateNum,newScore,analysis));
        }
        if (newScore > bestScore) {
          bestScore=newScore;
          bestStateNum=nextStateNum;
        }
      }
    }
    stateIds=nextStates;
  }
  LinkedList<String> best=Lists.newLinkedList();
  int stateNum=bestStateNum;
  while (stateNum > 0) {
    State s=bestPath.get(stateNum);
    best.addFirst(s.parse);
    stateNum=s.previous;
  }
  best.removeLast();
  return new ParseResult(best,bestScore);
}

Fixed version (ground truth):
/** 
 * Calculates the best path using Viterbi decoding.
 * @param sentence sentece with ambiguous wrods.
 * @param useAveragedWeights if true, average weights are used for scoring, else, normal weightsare used.
 * @return best parse sequence and its score.
 */
ParseResult bestParse(SentenceData sentence,boolean useAveragedWeights){
  sentence.allWordAnalyses.add(WordData.SENTENCE_END);
  IntValueMap<StateId> stateIds=new IntValueMap<>();
  UIntMap<State> bestPath=new UIntMap<>();
  bestPath.put(0,new State(-1,0,null));
  stateIds.put(new StateId("String_Node_Str","String_Node_Str"),0);
  int bestStateNum=0;
  float bestScore=-100000;
  int n=0;
  for (  WordData word : sentence.allWordAnalyses) {
    IntValueMap<StateId> nextStates=new IntValueMap<>();
    List<String> allAnalyses=Lists.newArrayList(word.allAnalyses);
    bestScore=-100000;
    for (    String analysis : allAnalyses) {
      for (      StateId id : stateIds) {
        int stateNum=stateIds.get(id);
        State state=bestPath.get(stateNum);
        List<String> trigram=Lists.newArrayList(id.first,id.second,analysis);
        IntValueMap<String> features=new IntValueMap<>();
        extractTrigramFeatures(trigram,features);
        float trigramScore=0;
        for (        String key : features) {
          if (useAveragedWeights) {
            trigramScore+=averagedWeights.weight(key) * features.get(key);
          }
 else {
            trigramScore+=weights.weight(key) * features.get(key);
          }
        }
        float newScore=trigramScore + state.score;
        StateId newStateId=new StateId(id.second,analysis);
        if (!nextStates.contains(newStateId)) {
          nextStates.put(newStateId,++n);
        }
        int nextStateNum=nextStates.get(newStateId);
        if (bestPath.containsKey(nextStateNum)) {
          State s=bestPath.get(nextStateNum);
          if (newScore > s.score) {
            bestPath.put(nextStateNum,new State(stateNum,newScore,analysis));
          }
        }
 else {
          bestPath.put(nextStateNum,new State(stateNum,newScore,analysis));
        }
        if (newScore > bestScore) {
          bestScore=newScore;
          bestStateNum=nextStateNum;
        }
      }
    }
    stateIds=nextStates;
  }
  LinkedList<String> best=Lists.newLinkedList();
  int stateNum=bestStateNum;
  while (stateNum > 0) {
    State s=bestPath.get(stateNum);
    best.addFirst(s.parse);
    stateNum=s.previous;
  }
  best.removeLast();
  return new ParseResult(best,bestScore);
}