Java Array Normalize normalizeLog(double[] logs)

Here you can find the source of normalizeLog(double[] logs)

Description

normalize Log

License

Open Source License

Declaration

public static void normalizeLog(double[] logs) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

public class Main {
    public static void normalizeLog(double[] logs) {
        double max = max(logs);
        double norm = 0.0;
        for (int i = 0; i < logs.length; i++) {
            norm += Math.exp(logs[i] - max);
        }//from   w  w  w. j av a  2  s  . co m
        norm = Math.log(norm) + max;
        add(logs, -norm);
        exp(logs);
    }

    private static double max(double[] a) {
        double m = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] > m) {
                m = a[i];
            }
        }
        return m;
    }

    private static void exp(double[] a) {
        for (int i = 0; i < a.length; i++) {
            a[i] = Math.exp(a[i]);
        }
    }

    public static void add(double[][][] a, double v) {
        for (int i = 0; i < a.length; i++) {
            add(a[i], v);
        }
    }

    public static void add(double[][] a, double v) {
        for (int i = 0; i < a.length; i++) {
            add(a[i], v);
        }
    }

    public static void add(double[] a, double v) {
        for (int i = 0; i < a.length; i++) {
            a[i] += v;
        }
    }

    public static void add(double[] target, double[] source) {
        if (target.length != source.length) {
            throw new IllegalArgumentException(
                    "Support sizes not equal: " + target.length + " != " + source.length);
        }

        for (int i = 0; i < target.length; i++) {
            target[i] += source[i];
        }
    }
}

Related

  1. normalizeHistogramToBase(int[] hist, double base)
  2. normalizeInnerPointDistanceMax(double[][] distances, double maxDist)
  3. normalizeL2(double[] a)
  4. normalizeL2(double[] histogram)
  5. normalizeLengthInPlace(double[] in)
  6. normalizeMatrix(double[][] M)
  7. normalizeMatrix(float[] cm)
  8. normalizeMemberNames(final String[] memberNames)
  9. normalizePositiveValues(double[][] array)