public int[] bestSequence(SequenceModel ts) {
    
    int[] sample = new int[ts.length()+ts.leftWindow()];

    for (int pos = ts.leftWindow(); pos < sample.length; pos++) {
      double[] scores = ts.scoresOf(sample, pos);
      double total = 0.0;
      for (int i = 0; i < scores.length; i++) {
        scores[i] = Math.exp(scores[i]);
      }
      ArrayMath.normalize(scores);
      int l = ArrayMath.sampleFromDistribution(scores);
      sample[pos] = ts.getPossibleValues(pos)[l];
    }

    return sample;
  }
public int [ ] bestSequence ( SequenceModel ts ) { int [ ] sample = new int [ ts . length ( ) + ts . leftWindow ( ) ] ; for ( int pos = ts . leftWindow ( ) ; pos < sample . length ; pos ++ ) { double [ ] scores = ts . scoresOf ( sample , pos ) ; double total = 0.0 ; for ( int i = 0 ; i < scores . length ; i ++ ) { scores [ i ] = Math . exp ( scores [ i ] ) ; } ArrayMath . normalize ( scores ) ; int l = ArrayMath . sampleFromDistribution ( scores ) ; sample [ pos ] = ts . getPossibleValues ( pos ) [ l ] ; } return sample ; }
Runs the Viterbi algorithm on the sequence model given by the TagScorer
in order to find the best sequence.
@return an array containing the int tags of the best sequence