Here you can find the source of normalize(double[] probDist)
public static double[] normalize(double[] probDist)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static double[] normalize(double[] probDist) { int len = probDist.length; double total = 0.0; for (double d : probDist) { total = total + d;//from w ww . j a va 2s . c o m } double[] normalized = new double[len]; if (total != 0) { for (int i = 0; i < len; i++) { normalized[i] = probDist[i] / total; } } return normalized; } public static List<Double> normalize(List<Double> values) { double[] valuesAsArray = new double[values.size()]; for (int i = 0; i < valuesAsArray.length; i++) { valuesAsArray[i] = values.get(i); } double[] normalized = normalize(valuesAsArray); List<Double> results = new ArrayList<Double>(); for (int i = 0; i < normalized.length; i++) { results.add(normalized[i]); } return results; } }