Java Array Normalize normalize(double[] d)

Here you can find the source of normalize(double[] d)

Description

Normalizes d .

License

Open Source License

Parameter

Parameter Description
d an array of non-negative values

Return

dPrime with d[i] / sum_{0 <= i < d.length} d[i]}

Declaration

public static double[] normalize(double[] d) 

Method Source Code

//package com.java2s;
/**/*from w w w  . j a  v a 2  s . c om*/
 * MiDEO: a framework to perform data mining on probabilistic condensed 
 * representations
 * Copyright (C) 2015 Michael Geilke
 *
 * This file is part of MiDEO.
 * 
 * MiDEO is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 * 
 * MiDEO is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

public class Main {
    /**
     * Normalizes {@code d}. It is assumed that {@code d} are
     * non-negative values.
     * @param d an array of non-negative values
     * @return dPrime with {@literal d[i] / sum_{0 <= i < d.length}
     * d[i]}
     */
    public static double[] normalize(double[] d) {
        double[] dPrime = new double[d.length];
        double sum = 0.0;
        for (int i = 0; i < d.length; i++) {
            sum += d[i];
        }
        for (int i = 0; i < dPrime.length; i++) {
            dPrime[i] = d[i] / sum;
        }
        return dPrime;
    }
}

Related

  1. normalize(double[] ar)
  2. normalize(double[] array)
  3. normalize(double[] array)
  4. normalize(double[] array)
  5. normalize(double[] bins)
  6. normalize(double[] data)
  7. normalize(double[] data, double floor)
  8. normalize(double[] descriptor)
  9. normalize(double[] doubleArray)