Java Array Sum sumLog(double[] logs)

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

Description

sum Log

License

Open Source License

Declaration

public static double sumLog(double[] logs) 

Method Source Code

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

public class Main {
    public static double sumLog(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 www .j  ava 2  s  . c  om
        norm = Math.log(norm) + max;
        return norm;
    }

    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]);
        }
    }
}

Related

  1. sumIntArray(int[] a)
  2. sumIntArray(int[] array)
  3. sumInts(int... numbers)
  4. sumList(int[] paramList)
  5. sumLLL(double a[], double b[], int bBegin, int bEnd)
  6. sumLog10(double[] log10values)
  7. sumLong(int[] array)
  8. summarizeIntegerArray(int[] numbers)
  9. summarizeNumbersAsString(int[] numbers)