Here you can find the source of normalize(double[] weights)
public static double[] normalize(double[] weights)
//package com.java2s; public class Main { /**//from w ww. ja v a 2 s .co m * Returns an array of doubles resulting from the normalization of a given * array of (positive) doubles. */ public static double[] normalize(double[] weights) { double[] result = new double[weights.length]; double sum = sum(weights); for (int i = 0; i != weights.length; i++) result[i] = weights[i] / sum; return result; } /** Returns the sum of an array of doubles. */ public static double sum(double[] array) { double result = 0; for (int i = 0; i != array.length; i++) result += array[i]; return result; } }