edu.stanford.nlp.stats
Class Counters

java.lang.Object
  extended by edu.stanford.nlp.stats.Counters

public class Counters
extends Object

Static methods for operating on Counters.

Author:
Galen Andrew (galand@cs.stanford.edu), Jeff Michels (jmichels@stanford.edu), dramage, cer

Method Summary
static
<E> Counter<E>
absoluteDifference(Counter<E> c1, Counter<E> c2)
          Returns |c1 - c2|.
static
<E> void
addInPlace(Counter<E> target, Counter<E> arg)
          Sets each value of target to be target[k]+arg[k] for all keys k in target.
static
<E> void
addInPlace(Counter<E> target, Counter<E> arg, double scale)
          Sets each value of target to be target[k]+scale*arg[k] for all keys k in target.
static
<T1,T2> void
addInPlace(TwoDimensionalCounter<T1,T2> target, TwoDimensionalCounter<T1,T2> arg)
          For all keys (u,v) in arg, sets target[u,v] to be target[u,v] + arg[u,v]
static
<T1,T2> void
addInPlace(TwoDimensionalCounter<T1,T2> target, TwoDimensionalCounter<T1,T2> arg, double scale)
          For all keys (u,v) in arg, sets target[u,v] to be target[u,v] + scale * arg[u,v]
static
<E> E
argmax(Counter<E> c)
          Finds and returns the key in this Counter with the largest count.
static
<E> E
argmin(Counter<E> c)
          Finds and returns the key in this Counter with the largest count.
static
<E> Counter<E>
asCounter(FixedPrioritiesPriorityQueue<E> p)
          Returns a counter whose keys are the elements in this priority queue, and whose counts are the priorities in this queue.
static
<E> Map<E,Double>
asMap(Counter<E> counter)
          Returns a map view of the given counter.
static
<E> Counter<E>
average(Counter<E> c1, Counter<E> c2)
          Returns a new Counter with counts averaged from the two given Counters.
static
<E> double
cosine(Counter<E> c1, Counter<E> c2)
           
static
<E> double
crossEntropy(Counter<E> from, Counter<E> to)
          Note that this implementation doesn't normalize the "from" Counter.
static ClassicCounter deserializeCounter(String filename)
           
static
<T> Counter<T>
diff(Counter<T> goldFeatures, Counter<T> guessedFeatures)
           
static
<E> void
divideInPlace(Counter<E> target, Counter<E> denominator)
          Divides every non-zero count in target by the corresponding value in the denominator Counter.
static
<E> Counter<E>
division(Counter<E> c1, Counter<E> c2)
          Returns c1 divided by c2.
static
<E> double
dotProduct(Counter<E> c1, Counter<E> c2)
          Returns the product of c1 and c2.
static
<E> double
entropy(Counter<E> c)
          Calculates the entropy of the given counter (in bits).
static
<E> boolean
equals(Counter<E> o1, Counter<E> o2)
          Default equality comparison for two counters potentially backed by alternative implementations.
static
<T> Counter<T>
exp(Counter<T> c)
           
static
<E,N extends Number>
Counter<E>
fromMap(Map<E,N> map)
          Returns a counter view of the given map.
static
<E,N extends Number>
Counter<E>
fromMap(Map<E,N> map, Class<N> type)
          Returns a counter view of the given map.
static
<E> Counter<Double>
getCountCounts(Counter<E> c)
           
static
<E> Counter<E>
intersection(Counter<E> c1, Counter<E> c2)
          Returns a counter that is the intersection of c1 and c2.
static
<E> double
jaccardCoefficient(Counter<E> c1, Counter<E> c2)
          Returns the Jaccard Coefficient of the two counters.
static
<E> double
jensenShannonDivergence(Counter<E> c1, Counter<E> c2)
          Calculates the Jensen-Shannon divergence between the two counters.
static
<E> Set<E>
keysAbove(Counter<E> c, double countThreshold)
          Returns the set of keys whose counts are at or above the given threshold.
static
<E> Set<E>
keysAt(Counter<E> c, double count)
          Returns the set of keys that have exactly the given count.
static
<E> Set<E>
keysBelow(Counter<E> c, double countThreshold)
          Returns the set of keys whose counts are at or below the given threshold.
static
<E> double
klDivergence(Counter<E> from, Counter<E> to)
          Calculates the KL divergence between the two counters.
static
<E,C extends Counter<E>>
C
L2Normalize(C c)
          L2 normalize a counter.
static
<E> Counter<E>
linearCombination(Counter<E> c1, double w1, Counter<E> c2, double w2)
          Returns a Counter which is a weighted average of c1 and c2.
static
<T1,T2> TwoDimensionalCounter<T1,T2>
load2DCounter(String filename, Class<T1> t1, Class<T2> t2)
           
static
<E> ClassicCounter<E>
loadCounter(String filename, Class<E> c)
          Loads a Counter from a text file.
static
<E> IntCounter<E>
loadIntCounter(String filename, Class<E> c)
          Loads a Counter from a text file.
static
<E> void
logInPlace(Counter<E> target)
           
static
<E> void
logNormalize(Counter<E> c)
           
static
<E> double
logSum(Counter<E> c)
          Returns ArrayMath.logSum of the values in this counter
static
<E> double
max(Counter<E> c)
          Returns the value of the maximum entry in this counter.
static
<E> double
mean(Counter<E> c)
          Returns the mean of all the counts (totalCount/size).
static
<E> double
min(Counter<E> c)
          Returns the value of the smallest entry in this counter.
static
<E> void
multiplyInPlace(Counter<E> target, Counter<E> term)
          Multiplies every count in target by the corresponding value in the term Counter.
static
<E> void
normalize(Counter<E> target)
          Normalizes the target counter in-place, so the sum of the resulting values equals 1.
static
<E,C extends Counter<E>>
C
perturbCounts(C c, Random random, double p)
           
static
<T> Counter<T>
pow(Counter<T> c, double temp)
           
static
<E> Counter<E>
powNormalized(Counter<E> c, double temp)
          Returns a counter where each element corresponds to the normalized count of the corresponding element in c raised to the given power.
static
<E> void
printCounterComparison(Counter<E> a, Counter<E> b)
          Great for debugging.
static
<E> void
printCounterComparison(Counter<E> a, Counter<E> b, PrintStream out)
          Great for debugging.
static
<E extends Comparable<E>>
void
printCounterSortedByKeys(Counter<E> c)
           
static
<E> Counter<E>
product(Counter<E> c1, Counter<E> c2)
          Returns the product of c1 and c2.
static
<E> E
restrictedArgMax(Counter<E> c, Collection<E> restriction)
           
static
<E> Set<E>
retainNonZeros(Counter<E> counter)
          Removes all entries with 0 count in the counter, returning the set of removed entries.
static
<E> void
retainTop(Counter<E> c, int num)
          Removes all entries from c except for the top num
static
<T> T
sample(Counter<T> c)
          Does not assumes c is normalized.
static
<T> T
sample(Counter<T> c, Random rand)
          Does not assumes c is normalized.
static
<T1,T2> void
save2DCounter(TwoDimensionalCounter<T1,T2> tdc, String filename)
           
static
<E> void
saveCounter(Counter<E> c, OutputStream stream)
          Saves a Counter as one key/count pair per line separated by white space to the given OutputStream.
static
<E> void
saveCounter(Counter<E> c, String filename)
          Saves a Counter to a text file.
static
<E,C extends Counter<E>>
C
scale(C c, double s)
          Returns a new Counter which is scaled by the given scale factor.
static
<T1,T2> TwoDimensionalCounter<T1,T2>
scale(TwoDimensionalCounter<T1,T2> c, double d)
          Creates a new TwoDimensionalCounter where all the counts are scaled by d.
static
<E> void
scaleInPlace(Counter<E> target, double scale)
          Multiplies each value in target by scale, in place.
static void serializeCounter(Counter c, String filename)
           
static
<E> double
skewDivergence(Counter<E> c1, Counter<E> c2, double skew)
          Calculates the skew divergence between the two counters.
static
<E> void
subtractInPlace(Counter<E> target, Counter<E> arg)
          Sets each value of target to be target[k]-arg[k] for all keys k in target.
static
<E> String
toBiggestValuesFirstString(Counter<E> c)
           
static
<E> String
toBiggestValuesFirstString(Counter<E> c, int k)
           
static
<T> String
toBiggestValuesFirstString(Counter<Integer> c, int k, Index<T> index)
           
static
<E> Comparator<E>
toComparator(Counter<E> counter)
          Returns a comparator backed by this counter: two objects are compared by their associated values stored in the counter.
static
<E> Comparator<E>
toComparatorDescending(Counter<E> counter)
           
static
<T> Counter<T>
toCounter(double[] counts, Index<T> index)
           
static
<E> Counter<E>
toCounter(Map<Integer,? extends Number> counts, Index<E> index)
          Turns the given map and index into a counter instance.
static
<E> PriorityQueue<E>
toPriorityQueue(Counter<E> c)
          Returns a PriorityQueue of the c where the score of the object is its priority.
static
<E> List<E>
toSortedList(Counter<E> c)
          A List of the keys in c, sorted from highest count to lowest.
static
<E> String
toString(Counter<E> counter, NumberFormat nf)
           
static
<E> String
toVerticalString(Counter<E> c)
           
static
<E> String
toVerticalString(Counter<E> c, int k)
           
static
<E> String
toVerticalString(Counter<E> c, int k, String fmt)
           
static
<E> String
toVerticalString(Counter<E> c, int k, String fmt, boolean swap)
          Returns a String representation of the k keys with the largest counts in the given Counter, using the given format string.
static
<E> String
toVerticalString(Counter<E> c, String fmt)
           
static
<T1,T2> Counter<T2>
transform(Counter<T1> c, Function<T1,T2> f)
          Returns the counter with keys modified according to function F.
static
<E,C extends Counter<E>>
C
union(C c1, C c2)
          Returns a Counter that is the union of the two Counters passed in (counts are added).
static
<T> Counter<T>
unmodifiableCounter(Counter<T> counter)
          Returns unmodifiable view of the counter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

logSum

public static <E> double logSum(Counter<E> c)
Returns ArrayMath.logSum of the values in this counter


logNormalize

public static <E> void logNormalize(Counter<E> c)

max

public static <E> double max(Counter<E> c)
Returns the value of the maximum entry in this counter.


min

public static <E> double min(Counter<E> c)
Returns the value of the smallest entry in this counter.


argmax

public static <E> E argmax(Counter<E> c)
Finds and returns the key in this Counter with the largest count. Returning null if count is empty.


argmin

public static <E> E argmin(Counter<E> c)
Finds and returns the key in this Counter with the largest count.


mean

public static <E> double mean(Counter<E> c)
Returns the mean of all the counts (totalCount/size).


addInPlace

public static <E> void addInPlace(Counter<E> target,
                                  Counter<E> arg,
                                  double scale)
Sets each value of target to be target[k]+scale*arg[k] for all keys k in target.


addInPlace

public static <E> void addInPlace(Counter<E> target,
                                  Counter<E> arg)
Sets each value of target to be target[k]+arg[k] for all keys k in target.


addInPlace

public static <T1,T2> void addInPlace(TwoDimensionalCounter<T1,T2> target,
                                      TwoDimensionalCounter<T1,T2> arg,
                                      double scale)
For all keys (u,v) in arg, sets target[u,v] to be target[u,v] + scale * arg[u,v]

Type Parameters:
T1 -
T2 -
Parameters:
target -
arg -
scale -

addInPlace

public static <T1,T2> void addInPlace(TwoDimensionalCounter<T1,T2> target,
                                      TwoDimensionalCounter<T1,T2> arg)
For all keys (u,v) in arg, sets target[u,v] to be target[u,v] + arg[u,v]

Type Parameters:
T1 -
T2 -
Parameters:
target -
arg -

subtractInPlace

public static <E> void subtractInPlace(Counter<E> target,
                                       Counter<E> arg)
Sets each value of target to be target[k]-arg[k] for all keys k in target.


divideInPlace

public static <E> void divideInPlace(Counter<E> target,
                                     Counter<E> denominator)
Divides every non-zero count in target by the corresponding value in the denominator Counter. Beware that this can give NaN values for zero counts in the denominator counter!


multiplyInPlace

public static <E> void multiplyInPlace(Counter<E> target,
                                       Counter<E> term)
Multiplies every count in target by the corresponding value in the term Counter.


scaleInPlace

public static <E> void scaleInPlace(Counter<E> target,
                                    double scale)
Multiplies each value in target by scale, in place.


normalize

public static <E> void normalize(Counter<E> target)
Normalizes the target counter in-place, so the sum of the resulting values equals 1.

Type Parameters:
E -
Parameters:
target -

logInPlace

public static <E> void logInPlace(Counter<E> target)

retainTop

public static <E> void retainTop(Counter<E> c,
                                 int num)
Removes all entries from c except for the top num


retainNonZeros

public static <E> Set<E> retainNonZeros(Counter<E> counter)
Removes all entries with 0 count in the counter, returning the set of removed entries.


keysAbove

public static <E> Set<E> keysAbove(Counter<E> c,
                                   double countThreshold)
Returns the set of keys whose counts are at or above the given threshold. This set may have 0 elements but will not be null.


keysBelow

public static <E> Set<E> keysBelow(Counter<E> c,
                                   double countThreshold)
Returns the set of keys whose counts are at or below the given threshold. This set may have 0 elements but will not be null.


keysAt

public static <E> Set<E> keysAt(Counter<E> c,
                                double count)
Returns the set of keys that have exactly the given count. This set may have 0 elements but will not be null.


transform

public static <T1,T2> Counter<T2> transform(Counter<T1> c,
                                            Function<T1,T2> f)
Returns the counter with keys modified according to function F. Eager evaluation.


toComparator

public static <E> Comparator<E> toComparator(Counter<E> counter)
Returns a comparator backed by this counter: two objects are compared by their associated values stored in the counter.


toComparatorDescending

public static <E> Comparator<E> toComparatorDescending(Counter<E> counter)

toSortedList

public static <E> List<E> toSortedList(Counter<E> c)
A List of the keys in c, sorted from highest count to lowest.

Parameters:
c -
Returns:
A List of the keys in c, sorted from highest count to lowest.

toPriorityQueue

public static <E> PriorityQueue<E> toPriorityQueue(Counter<E> c)
Returns a PriorityQueue of the c where the score of the object is its priority.


union

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

Parameters:
c1 -
c2 -
Returns:
A Counter that is the union of the two Counters passed in (counts are added).

intersection

public static <E> Counter<E> intersection(Counter<E> c1,
                                          Counter<E> c2)
Returns a counter that is the intersection of c1 and c2. If both c1 and c2 contain a key, the min of the two counts is used.

Parameters:
c1 -
c2 -
Returns:
A counter that is the intersection of c1 and c2

jaccardCoefficient

public static <E> double jaccardCoefficient(Counter<E> c1,
                                            Counter<E> c2)
Returns the Jaccard Coefficient of the two counters. Calculated as |c1 intersect c2| / ( |c1| + |c2| - |c1 intersect c2|

Parameters:
c1 -
c2 -
Returns:
The Jaccard Coefficient of the two counters

product

public static <E> Counter<E> product(Counter<E> c1,
                                     Counter<E> c2)
Returns the product of c1 and c2.

Parameters:
c1 -
c2 -
Returns:
The product of c1 and c2.

dotProduct

public static <E> double dotProduct(Counter<E> c1,
                                    Counter<E> c2)
Returns the product of c1 and c2.

Parameters:
c1 -
c2 -
Returns:
The product of c1 and c2.

absoluteDifference

public static <E> Counter<E> absoluteDifference(Counter<E> c1,
                                                Counter<E> c2)
Returns |c1 - c2|.

Parameters:
c1 -
c2 -
Returns:
The difference between sets c1 and c2.

division

public static <E> Counter<E> division(Counter<E> c1,
                                      Counter<E> c2)
Returns c1 divided by c2. Note that this can create NaN if c1 has non-zero counts for keys that c2 has zero counts.

Parameters:
c1 -
c2 -
Returns:
c1 divided by c2.

entropy

public static <E> double entropy(Counter<E> 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)

crossEntropy

public static <E> double crossEntropy(Counter<E> from,
                                      Counter<E> to)
Note that this implementation doesn't normalize the "from" Counter. It does, however, normalize the "to" Counter. Result is meaningless if any of the counts are negative.

Returns:
The cross entropy of H(from, to)

klDivergence

public static <E> double klDivergence(Counter<E> from,
                                      Counter<E> 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 any of the counts are negative. In other words, how well can c1 be represented by c2. if there is some value in c1 that gets zero prob in c2, then return positive infinity.

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

jensenShannonDivergence

public static <E> double jensenShannonDivergence(Counter<E> c1,
                                                 Counter<E> c2)
Calculates the Jensen-Shannon divergence between the two counters. That is, it calculates 1/2 [KL(c1 || avg(c1,c2)) + KL(c2 || avg(c1,c2))] .

Parameters:
c1 -
c2 -
Returns:
The Jensen-Shannon divergence between the distributions

skewDivergence

public static <E> double skewDivergence(Counter<E> c1,
                                        Counter<E> c2,
                                        double skew)
Calculates the skew divergence between the two counters. That is, it calculates KL(c1 || (c2*skew + c1*(1-skew))) . In other words, how well can c1 be represented by a "smoothed" c2.

Parameters:
c1 -
c2 -
skew -
Returns:
The skew divergence between the distributions

L2Normalize

public static <E,C extends Counter<E>> C L2Normalize(C c)
L2 normalize a counter.

Parameters:
c - the Counter to be L2 normalized.

cosine

public static <E> double cosine(Counter<E> c1,
                                Counter<E> c2)

average

public static <E> Counter<E> average(Counter<E> c1,
                                     Counter<E> 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 <E> Counter<E> linearCombination(Counter<E> c1,
                                               double w1,
                                               Counter<E> 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.


perturbCounts

public static <E,C extends Counter<E>> C perturbCounts(C c,
                                                       Random random,
                                                       double p)

printCounterComparison

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

Parameters:
a -
b -

printCounterComparison

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

Parameters:
a -
b -

getCountCounts

public static <E> Counter<Double> getCountCounts(Counter<E> c)

scale

public static <E,C extends Counter<E>> C scale(C c,
                                               double s)
Returns a new Counter which is scaled by the given scale factor.


printCounterSortedByKeys

public static <E extends Comparable<E>> void printCounterSortedByKeys(Counter<E> c)

loadCounter

public static <E> ClassicCounter<E> loadCounter(String filename,
                                                Class<E> c)
                                     throws RuntimeException
Loads a Counter from a text file. File must have the format of one key/count pair per line, separated by whitespace.

Parameters:
filename - the path to the file to load the Counter from
c - the Class to instantiate each member of the set. Must have a String constructor.
Returns:
The counter loaded from the file.
Throws:
RuntimeException

loadIntCounter

public static <E> IntCounter<E> loadIntCounter(String filename,
                                               Class<E> c)
                                    throws Exception
Loads a Counter from a text file. File must have the format of one key/count pair per line, separated by whitespace.

Parameters:
filename - the path to the file to load the Counter from
c - the Class to instantiate each member of the set. Must have a String constructor.
Returns:
The counter loaded from the file.
Throws:
Exception

saveCounter

public static <E> void saveCounter(Counter<E> c,
                                   OutputStream stream)
Saves a Counter as one key/count pair per line separated by white space to the given OutputStream. Does not close the stream.


saveCounter

public static <E> void saveCounter(Counter<E> c,
                                   String filename)
                        throws IOException
Saves a Counter to a text file. Counter written as one key/count pair per line, separated by whitespace.

Throws:
IOException

load2DCounter

public static <T1,T2> TwoDimensionalCounter<T1,T2> load2DCounter(String filename,
                                                                 Class<T1> t1,
                                                                 Class<T2> t2)
                                                  throws RuntimeException
Throws:
RuntimeException

save2DCounter

public static <T1,T2> void save2DCounter(TwoDimensionalCounter<T1,T2> tdc,
                                         String filename)
                          throws IOException
Throws:
IOException

serializeCounter

public static void serializeCounter(Counter c,
                                    String filename)
                             throws IOException
Throws:
IOException

deserializeCounter

public static ClassicCounter deserializeCounter(String filename)
                                         throws Exception
Throws:
Exception

toString

public static <E> String toString(Counter<E> counter,
                                  NumberFormat nf)

toBiggestValuesFirstString

public static <E> String toBiggestValuesFirstString(Counter<E> c)

toBiggestValuesFirstString

public static <E> String toBiggestValuesFirstString(Counter<E> c,
                                                    int k)

toBiggestValuesFirstString

public static <T> String toBiggestValuesFirstString(Counter<Integer> c,
                                                    int k,
                                                    Index<T> index)

toVerticalString

public static <E> String toVerticalString(Counter<E> c)

toVerticalString

public static <E> String toVerticalString(Counter<E> c,
                                          int k)

toVerticalString

public static <E> String toVerticalString(Counter<E> c,
                                          String fmt)

toVerticalString

public static <E> String toVerticalString(Counter<E> c,
                                          int k,
                                          String fmt)

toVerticalString

public static <E> String toVerticalString(Counter<E> c,
                                          int k,
                                          String fmt,
                                          boolean swap)
Returns a String representation of the k keys with the largest counts in the given Counter, using the given format string.

Parameters:
c - a Counter
k - how many keys to print
fmt - a format string, such as "%.0f\t%s" (do not include final "%n")
swap - whether the count should appear after the key

restrictedArgMax

public static <E> E restrictedArgMax(Counter<E> c,
                                     Collection<E> restriction)
Parameters:
c -
restriction -
Returns:
Returns the maximum element of c that is within the restriction Collection

toCounter

public static <T> Counter<T> toCounter(double[] counts,
                                       Index<T> index)

toCounter

public static <E> Counter<E> toCounter(Map<Integer,? extends Number> counts,
                                       Index<E> index)
Turns the given map and index into a counter instance. For each entry in counts, its key is converted to a counter key via lookup in the given index.


scale

public static <T1,T2> TwoDimensionalCounter<T1,T2> scale(TwoDimensionalCounter<T1,T2> c,
                                                         double d)
Creates a new TwoDimensionalCounter where all the counts are scaled by d. Internally, uses Counters.scale();

Parameters:
c -
d -
Returns:
The TwoDimensionalCounter

sample

public static <T> T sample(Counter<T> c,
                           Random rand)
Does not assumes c is normalized.

Parameters:
c -
rand -
Returns:
A sample from c

sample

public static <T> T sample(Counter<T> c)
Does not assumes c is normalized.

Parameters:
c -
Returns:
A sample from c

powNormalized

public static <E> Counter<E> powNormalized(Counter<E> c,
                                           double temp)
Returns a counter where each element corresponds to the normalized count of the corresponding element in c raised to the given power.


pow

public static <T> Counter<T> pow(Counter<T> c,
                                 double temp)

exp

public static <T> Counter<T> exp(Counter<T> c)

diff

public static <T> Counter<T> diff(Counter<T> goldFeatures,
                                  Counter<T> guessedFeatures)

equals

public static <E> boolean equals(Counter<E> o1,
                                 Counter<E> o2)
Default equality comparison for two counters potentially backed by alternative implementations.


unmodifiableCounter

public static <T> Counter<T> unmodifiableCounter(Counter<T> counter)
Returns unmodifiable view of the counter. changes to the underlying Counter are written through to this Counter.

Parameters:
counter - The counter
Returns:
unmodifiable view of the counter

asCounter

public static <E> Counter<E> asCounter(FixedPrioritiesPriorityQueue<E> p)
Returns a counter whose keys are the elements in this priority queue, and whose counts are the priorities in this queue. In the event there are multiple instances of the same element in the queue, the counter's count will be the sum of the instances' priorities.


fromMap

public static <E,N extends Number> Counter<E> fromMap(Map<E,N> map)
Returns a counter view of the given map. Infers the numeric type of the values from the first element in map.values().


fromMap

public static <E,N extends Number> Counter<E> fromMap(Map<E,N> map,
                                                      Class<N> type)
Returns a counter view of the given map. The type parameter is the type of the values in the map, which because of Java's generics type erasure, can't be discovered by reflection if the map is currently empty.


asMap

public static <E> Map<E,Double> asMap(Counter<E> counter)
Returns a map view of the given counter.



Stanford NLP Group