Java Array Normalize normalize(double[] in)

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

Description

Complexity: O( 2 * N ) Should in contain only one unique number, this method return an array of 0's

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**Complexity: O( 2 * N )
     * /* w  w  w.j  a  v  a  2  s  .  c  om*/
     * Should in contain only one unique number, this method return an array of 0's
     */
    public static double[] normalize(double[] in) {
        double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;

        //Find minimum and maximum value in the array
        for (double val : in) {
            if (val > max)
                max = val;
            if (val < min)
                min = val;
        }
        return normalize(in, min, max);
    }

    /**Complexity: O( N )
     *
     * Should min == max, this method return an array of 0's
     */
    public static double[] normalize(double[] in, double min, double max) {

        //Create normalized data
        double[] out = new double[in.length];
        for (int i = 0; i < out.length; i++) {
            out[i] = normalize(in[i], min, max);
        }

        return out;
    }

    /**Complexity: O( 1 )
     */
    public static double normalize(double in, double min, double max) {
        return min == max ? 0 : (in - min) / (max - min);
    }
}

Related

  1. normalize(double[] doubles)
  2. normalize(double[] doubles)
  3. normalize(double[] doubles, double sum)
  4. normalize(double[] doubles, double sum)
  5. normalize(double[] in)
  6. normalize(double[] point, double[] uni, double[] unideltas)
  7. normalize(double[] points)
  8. normalize(double[] probDist)
  9. normalize(double[] state)