Here you can find the source of normalize(double[] values)
Parameter | Description |
---|---|
values | a parameter |
public static double[] normalize(double[] values)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; public class Main { /**//from w w w . j a v a 2 s.c om * Normalize to a distribution in which the sum of all the elements is 1 * * @param values * @return */ public static double[] normalize(double[] values) { double sum = sum(values); double[] norm = new double[values.length]; for (int i = 0; i < norm.length; i++) { norm[i] = values[i] / sum; } return norm; } public static double sum(ArrayList<Double> values) { double sum = 0; for (double value : values) { sum += value; } return sum; } public static double sum(double[] values) { double sum = 0; for (double value : values) { sum += value; } return sum; } public static int sum(int[] values) { int sum = 0; for (int value : values) { sum += value; } return sum; } }