Java Array Normalize normalizeProb(double[] prob)

Here you can find the source of normalizeProb(double[] prob)

Description

normalize probabilities and check convergence by the maximum probability

License

Apache License

Return

maximum of probabilities

Declaration

public static double normalizeProb(double[] prob) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   w  w w  .j  av  a2  s . co  m*/
     * normalize probabilities and check convergence by the maximum probability
     * @return maximum of probabilities
     */
    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;
    }
}

Related

  1. normalizeLog(double[] logs)
  2. normalizeMatrix(double[][] M)
  3. normalizeMatrix(float[] cm)
  4. normalizeMemberNames(final String[] memberNames)
  5. normalizePositiveValues(double[][] array)
  6. normalizeRecorderColumn(int column, int tabSize, int[] tabIndices)
  7. normalizeRows(float[][] input)
  8. normalizeSpaces(char[] buf, int origStart, int origEnd)
  9. normalizeTo(float[] in, float normsum)