Java mean meanEnt(double[] nums)

Here you can find the source of meanEnt(double[] nums)

Description

Return the mean entropy of the logs of the numbers given.

License

Open Source License

Parameter

Parameter Description
nums the numbers

Return

sum of logs of numbers

Declaration

public static double meanEnt(double[] nums) 

Method Source Code

//package com.java2s;
/*/*from   ww w .j  a va2  s.  co m*/
 Copyright (C) 2010, 2011 Constantine Lignos

 This file is a part of CATS.

 CATS 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.

 CATS 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 CATS.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Return the mean entropy of the logs of the numbers given.
     * @param nums the numbers
     * @return sum of logs of numbers
     */
    public static double meanEnt(double[] nums) {
        return logProb(nums) / nums.length;
    }

    /**
     * Return the sum of the logs of the numbers given.
     * @param nums the numbers
     * @return sum of logs of numbers
     */
    public static double logProb(double[] nums) {
        double sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += Math.log(nums[i]);
        }
        return sum;
    }
}

Related

  1. meanAndStandardDeviation(final double[] inp, final int startIndex, final int pastEnd)
  2. meanAndVariance(double[] a, boolean useUnbiasedEstimate)
  3. meanArithmetic(LinkedList a)
  4. meanArray(double[] arr)
  5. meandiff(double[] v1, double[] v2)
  6. meanFast(final double[] values)
  7. meanFilter(float[] weights, int context)
  8. meanGreenwichSideralTime(double t)
  9. meanImage(float[][]... images)