Java Collection Element Get getEntropy(Collection values)

Here you can find the source of getEntropy(Collection values)

Description

get Entropy

License

Open Source License

Declaration

public static double getEntropy(Collection<Double> values) 

Method Source Code

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

import java.util.Collection;

public class Main {
    public static double getEntropy(Collection<Double> values) {
        if (values.isEmpty()) {
            return -1.0;
        }//from  w  w  w  .  j  ava 2s  . c om

        double noOfTerms = 0;
        for (Double frequency : values) {
            noOfTerms += frequency;
        }

        double entropy = 0.0;
        for (Double frequency : values) {
            double currentProbability = frequency / noOfTerms;
            entropy += -currentProbability * Math.log(currentProbability) / Math.log(2);
        }

        return entropy;
    }
}

Related

  1. getComponentName(Collection existingNames, String name)
  2. getDocIdString(Collection docIds)
  3. getElement(final int index, final Collection coll)
  4. getElementClass(Collection collection)
  5. getElementFromSize1(Collection collection)
  6. getEnumNames( Collection values)
  7. getFlatString(Collection elements)
  8. getGivenClassObject(Collection coll, Class clazz)
  9. getHighest(final Collection elements, final Comparator c)