edu.stanford.nlp.util
Class Counters

java.lang.Object
  extended byedu.stanford.nlp.util.Counters

public class Counters
extends Object

Static methods for operating on Counters.

Author:
Galen Andrew (galand@cs.stanford.edu)

Constructor Summary
Counters()
           
 
Method Summary
static Counter average(Counter c1, Counter c2)
          Returns a new Counter with counts averaged from the two given Counters.
static double cosine(Counter c1, Counter c2)
           
static Counter createCounterFromList(List l)
           
static double entropy(Counter c)
          Calculates the entropy of the given counter (in bits).
static Counter getCountCounts(Counter c)
           
static double informationRadius(Counter c1, Counter c2)
          Calculates the information radius (aka the Jensen-Shannon divergence) between the two Counters.
static double klDivergence(Counter from, Counter to)
          Calculates the KL divergence between the two counters.
static Counter linearCombination(Counter c1, double w1, Counter c2, double w2)
          Returns a Counter which is a weighted average of c1 and c2.
static void printCounterComparison(Counter a, Counter b)
          Great for debugging.
static void printCounterComparison(Counter a, Counter b, PrintStream out)
          Great for debugging.
static void printCounterSortedByKeys(Counter c)
           
static PriorityQueue toPriorityQueue(Counter c)
           
static List toSortedList(Counter c)
           
static Counter union(Counter c1, Counter c2)
          Returns a Counter that is the union of the two Counters passed in (counts are added).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Counters

public Counters()
Method Detail

union

public static Counter union(Counter c1,
                            Counter c2)
Returns a Counter that is the union of the two Counters passed in (counts are added).

Parameters:
c1 -
c2 -
Returns:

entropy

public static double entropy(Counter c)
Calculates the entropy of the given counter (in bits). This method internally uses normalized counts (so they sum to one), but the value returned is meaningless if some of the counts are negative.

Returns:
The entropy of the given counter (in bits)

klDivergence

public static double klDivergence(Counter from,
                                  Counter to)
Calculates the KL divergence between the two counters. That is, it calculates KL(from || to). This method internally uses normalized counts (so they sum to one), but the value returned is meaningless if some of the counts are negative.

Parameters:
from -
to -
Returns:
The KL divergence between the distributions

informationRadius

public static double informationRadius(Counter c1,
                                       Counter c2)
Calculates the information radius (aka the Jensen-Shannon divergence) between the two Counters. This measure is defined as:
iRad(p,q) = D(p||(p+q)/2)+D(q,(p+q)/2)
where p is one Counter, q is the other counter, and D(p||q) is the KL divergence bewteen p and q. Note that iRad(p,q) = iRad(q,p).

Returns:
The information radius between the distributions

cosine

public static double cosine(Counter c1,
                            Counter c2)

average

public static Counter average(Counter c1,
                              Counter c2)
Returns a new Counter with counts averaged from the two given Counters. The average Counter will contain the union of keys in both source Counters, and each count will be the average of the two source counts for that key, where as usual a missing count in one Counter is treated as count 0.

Returns:
A new counter with counts that are the mean of the resp. counts in the given counters.

linearCombination

public static Counter linearCombination(Counter c1,
                                        double w1,
                                        Counter c2,
                                        double w2)
Returns a Counter which is a weighted average of c1 and c2. Counts from c1 are weighted with weight w1 and counts from c2 are weighted with w2.


createCounterFromList

public static Counter createCounterFromList(List l)

toSortedList

public static List toSortedList(Counter c)

toPriorityQueue

public static PriorityQueue toPriorityQueue(Counter c)

printCounterComparison

public static void printCounterComparison(Counter a,
                                          Counter b)
Great for debugging.

Parameters:
a -
b -

printCounterComparison

public static void printCounterComparison(Counter a,
                                          Counter b,
                                          PrintStream out)
Great for debugging.

Parameters:
a -
b -

getCountCounts

public static Counter getCountCounts(Counter c)

printCounterSortedByKeys

public static void printCounterSortedByKeys(Counter c)


Stanford NLP Group