Here you can find the source of normalize(double[] data, double floor)
public static void normalize(double[] data, double floor)
//package com.java2s; //License from project: Apache License public class Main { public static boolean normalize(float[] data) { float sum = 0; for (float x : data) sum += x;//ww w . j a va 2 s.com if (sum == 0) return false; for (int i = 0; i < data.length; i++) data[i] /= sum; return true; } public static boolean normalize(double[] data) { double sum = 0; for (double x : data) sum += x; if (sum == 0) return false; for (int i = 0; i < data.length; i++) data[i] /= sum; return true; } public static boolean normalize(double[][] data) { double sum = 0; for (double[] v : data) for (double x : v) sum += x; if (sum == 0) return false; for (double[] v : data) for (int i = 0; i < v.length; i++) v[i] /= sum; return true; } public static boolean normalize(double[][][] data) { double sum = 0; for (double[][] m : data) for (double[] v : m) for (double x : v) sum += x; if (sum == 0) return false; for (double[][] m : data) for (double[] v : m) for (int i = 0; i < v.length; i++) v[i] /= sum; return true; } public static void normalize(double[] data, double floor) { double sum = 0; for (double x : data) sum += x; // if (sum == 0) return; for (int i = 0; i < data.length; i++) { if (sum != 0) data[i] /= sum; if (data[i] < floor) data[i] = floor; } } }