code: private void forward(int[] o, double[][] alpha, double[] scaling) {
          for (int k = 0; k < numStates; k++) {
              alpha[0][k] = pi[k] * b[k][o[0]];
          }
          scale(scaling, alpha, 0);
  
          for (int t = 1; t < o.length; t++) {
              for (int k = 0; k < numStates; k++) {
                  double sum = 0.0;
  
                  for (int i = 0; i < numStates; i++) {
                      sum += alpha[t - 1][i] * a[i][k];
                  }
  
                  alpha[t][k] = sum * b[k][o[t]];
              }
              scale(scaling, alpha, t);
          }
      }
docs: Scaled forward procedure without underflow.
  
  @param o an observation sequence.
  @param alpha on output, alpha(i, j) holds the scaled total probability of
  ending up in state i at time j.
  @param scaling on output, it holds scaling factors.