Java List Average averageLog(List logList)

Here you can find the source of averageLog(List logList)

Description

average Log

License

Open Source License

Declaration

public static double averageLog(List<Double> logList) 

Method Source Code

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

import java.util.List;

public class Main {
    public static double averageLog(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  .  ja  va2  s  . c  om
        norm = Math.log(norm) + max;
        return norm - Math.log(logs.length);
    }

    public static double averageLog(List<Double> logList) {
        if (logList.size() == 1)
            return logList.get(0);

        double[] logs = new double[logList.size()];
        for (int i = 0; i < logs.length; i++) {
            logs[i] = logList.get(i);
        }
        return averageLog(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]);
        }
    }
}

Related

  1. average(List list)
  2. average(List numbers)
  3. average(List observations)
  4. average(List collection)
  5. averageDouble(final List values)
  6. averageValue(List oper)
  7. calculateAverage(final List durations)
  8. calculateAverage(List list)
  9. computeAverage(List aList)