Forward and backward terms, Viterbi algorithm in hidden Markov model implemented by Java