code: public static double normalizeProb(double[] prob) {
          double maxp = 0, sump = 0;
          for(int i=0;i<prob.length;++i) sump += prob[i];
          for(int i=0;i<prob.length;++i) {
              double p = prob[i] / sump;
              if (maxp < p) maxp = p;
              prob[i] = p;
          }
          return maxp;
      }
docs: normalize probabilities and check convergence by the maximum probability
  @return maximum of probabilities