private void doOutsideScores(){
  grammar.logarithmMode();
  lexicon.logarithmMode();
  for (int diff=length; diff >= 1; diff--) {
    for (int start=0; start + diff <= length; start++) {
      int end=start + diff;
      for (int s=0; s < numStates; s++) {
        double oS=oScore[start][end][s];
        if (Double.isInfinite(oS)) {
          continue;
        }
        UnaryRule[] rules=grammar.getClosedViterbiUnaryRulesByParent(s);
        for (int r=0; r < rules.length; r++) {
          UnaryRule ur=rules[r];
          double pS=ur.getScore(0,0);
          double tot=oS + pS;
          touchedRules++;
          if (tot > oScore[start][end][ur.childState] && iScore[start][end][ur.childState] > Double.NEGATIVE_INFINITY) {
            oScore[start][end][ur.childState]=tot;
          }
        }
      }
      for (int s=0; s < numStates; s++) {
        BinaryRule[] rules=grammar.splitRulesWithP(s);
        for (int r=0; r < rules.length; r++) {
          BinaryRule br=rules[r];
          double oS=oScore[start][end][br.parentState];
          if (Double.isInfinite(oS)) {
            continue;
          }
          int min1=narrowRExtent[start][br.leftChildState];
          if (end < min1) {
            continue;
          }
          int max1=narrowLExtent[end][br.rightChildState];
          if (max1 < min1) {
            continue;
          }
          int min=min1;
          int max=max1;
          if (max - min > 2) {
            int min2=wideLExtent[end][br.rightChildState];
            min=(min1 > min2 ? min1 : min2);
            if (max1 < min) {
              continue;
            }
            int max2=wideRExtent[start][br.leftChildState];
            max=(max1 < max2 ? max1 : max2);
            if (max < min) {
              continue;
            }
          }
          double pS=br.getScore(0,0,0);
          for (int split=min; split <= max; split++) {
            double lS=iScore[start][split][br.leftChildState];
            if (Double.isInfinite(lS)) {
              continue;
            }
            double rS=iScore[split][end][br.rightChildState];
            if (Double.isInfinite(rS)) {
              continue;
            }
            double totL=pS + rS + oS;
            touchedRules++;
            if (totL > oScore[start][split][br.leftChildState]) {
              oScore[start][split][br.leftChildState]=totL;
            }
            double totR=pS + lS + oS;
            if (totR > oScore[split][end][br.rightChildState]) {
              oScore[split][end][br.rightChildState]=totR;
            }
          }
        }
      }
    }
  }
}

private void doOutsideScores ( ) { grammar . logarithmMode ( ) ; lexicon . logarithmMode ( ) ; for ( int diff = length ; diff >= 1 ; diff -- ) { for ( int start = 0 ; start + diff <= length ; start ++ ) { int end = start + diff ; for ( int s = 0 ; s < numStates ; s ++ ) { double oS = oScore [ start ] [ end ] [ s ] ; if ( Double . isInfinite ( oS ) ) { continue ; } UnaryRule [ ] rules = grammar . getClosedViterbiUnaryRulesByParent ( s ) ; for ( int r = 0 ; r < rules . length ; r ++ ) { UnaryRule ur = rules [ r ] ; double pS = ur . getScore ( 0 , 0 ) ; double tot = oS + pS ; touchedRules ++ ; if ( tot > oScore [ start ] [ end ] [ ur . childState ] && iScore [ start ] [ end ] [ ur . childState ] > Double . NEGATIVE_INFINITY ) { oScore [ start ] [ end ] [ ur . childState ] = tot ; } } } for ( int s = 0 ; s < numStates ; s ++ ) { BinaryRule [ ] rules = grammar . splitRulesWithP ( s ) ; for ( int r = 0 ; r < rules . length ; r ++ ) { BinaryRule br = rules [ r ] ; double oS = oScore [ start ] [ end ] [ br . parentState ] ; if ( Double . isInfinite ( oS ) ) { continue ; } int min1 = narrowRExtent [ start ] [ br . leftChildState ] ; if ( end < min1 ) { continue ; } int max1 = narrowLExtent [ end ] [ br . rightChildState ] ; if ( max1 < min1 ) { continue ; } int min = min1 ; int max = max1 ; if ( max - min > 2 ) { int min2 = wideLExtent [ end ] [ br . rightChildState ] ; min = ( min1 > min2 ? min1 : min2 ) ; if ( max1 < min ) { continue ; } int max2 = wideRExtent [ start ] [ br . leftChildState ] ; max = ( max1 < max2 ? max1 : max2 ) ; if ( max < min ) { continue ; } } double pS = br . getScore ( 0 , 0 , 0 ) ; for ( int split = min ; split <= max ; split ++ ) { double lS = iScore [ start ] [ split ] [ br . leftChildState ] ; if ( Double . isInfinite ( lS ) ) { continue ; } double rS = iScore [ split ] [ end ] [ br . rightChildState ] ; if ( Double . isInfinite ( rS ) ) { continue ; } double totL = pS + rS + oS ; touchedRules ++ ; if ( totL > oScore [ start ] [ split ] [ br . leftChildState ] ) { oScore [ start ] [ split ] [ br . leftChildState ] = totL ; } double totR = pS + lS + oS ; if ( totR > oScore [ split ] [ end ] [ br . rightChildState ] ) { oScore [ split ] [ end ] [ br . rightChildState ] = totR ; } } } } } } }
calculate outside scores using internal arrays . note : this places the grammar and lexicon into logarithm mode !
