public class Counter<E>
extends java.lang.Object
implements java.io.Serializable
Constructor and Description |
---|
Counter() |
Counter(boolean identityHashMap) |
Counter(java.util.Collection<? extends E> collection) |
Counter(Counter<? extends E> counter) |
Counter(java.util.Map<? extends E,java.lang.Double> mapCounts) |
Counter(MapFactory<E,java.lang.Double> mf) |
Modifier and Type | Method and Description |
---|---|
boolean |
approxEquals(Counter<E> other,
double tol) |
E |
argMax()
Finds the key with maximum count.
|
PriorityQueue<E> |
asMinPriorityQueue()
Warning: all priorities are the negative of their counts in the counter
here
|
PriorityQueue<E> |
asPriorityQueue()
Builds a priority queue whose elements are the counter's elements, and
whose priorities are those elements' counts in the counter.
|
void |
clear() |
boolean |
containsKey(E key)
Returns whether the counter contains the given key.
|
Counter<E> |
difference(Counter<E> counter) |
double |
dotProduct(Counter<E> other) |
java.util.Set<java.util.Map.Entry<E,java.lang.Double>> |
entrySet() |
boolean |
equals(java.lang.Object o) |
double |
getCount(E key)
Get the count of the element, or zero if the element is not in the
counter.
|
double |
getDeflt() |
java.util.Set<java.util.Map.Entry<E,java.lang.Double>> |
getEntrySet() |
double |
getProbability(E key)
I know, I know, this should be wrapped in a Distribution class, but it's
such a common use...why not.
|
java.util.List<E> |
getSortedKeys() |
int |
hashCode() |
void |
incrementAll(java.util.Collection<? extends E> collection,
double count)
Increment each element in a given collection by a given amount.
|
<T extends E> |
incrementAll(Counter<T> counter) |
double |
incrementCount(E key,
double increment)
Increment a key's count by the given amount.
|
boolean |
isEmpty()
True if there are no entries in the counter (false does not mean
totalCount > 0)
|
boolean |
isEqualTo(Counter<E> counter) |
void |
keepBottomNKeys(int keepN) |
void |
keepTopNKeys(int keepN) |
java.util.Set<E> |
keySet()
The elements in the counter.
|
static void |
main(java.lang.String[] args) |
double |
max() |
double |
min() |
void |
normalize()
Destructively normalize this Counter in place.
|
void |
pruneKeysBelowThreshold(double cutoff) |
void |
put(E key,
double count,
boolean keepHigher)
Set the count for the given key if it is larger than the previous one;
|
void |
removeKey(E key) |
protected void |
removeKeyFromEntries(E key) |
E |
sample()
Will return a sample from the counter, will throw exception if any of the
counts are < 0.0 or if the totalCount() <= 0.0
|
E |
sample(java.util.Random rand)
Will return a sample from the counter, will throw exception if any of the
counts are < 0.0 or if the totalCount() <= 0.0
|
void |
scale(double c) |
Counter<E> |
scaledClone(double c) |
void |
setAllCounts(double val)
Sets all counts to the given value, but does not remove any keys
|
void |
setCount(E key,
double count)
Set the count for the given key, clobbering any previous count.
|
void |
setDeflt(double deflt) |
void |
setDirty(boolean dirty) |
void |
setMaxCount(E key,
double val)
Set's the key's count to the maximum of the current count and val.
|
void |
setMinCount(E key,
double val)
Set's the key's count to the minimum of the current count and val.
|
int |
size()
The number of entries in the counter (not the total count -- use
totalCount() instead).
|
Counter<E> |
toLogSpace() |
java.lang.String |
toString()
Returns a string representation with the keys ordered by decreasing
counts.
|
java.lang.String |
toString(int maxKeysToPrint)
Returns a string representation which includes no more than the
maxKeysToPrint elements with largest counts.
|
java.lang.String |
toString(int maxKeysToPrint,
boolean multiline)
Returns a string representation which includes no more than the
maxKeysToPrint elements with largest counts and optionally prints
one element per line.
|
java.lang.String |
toStringSortedByKeys() |
java.lang.String |
toStringTabSeparated() |
double |
totalCount()
Finds the total of all counts in the counter.
|
public Counter()
public Counter(boolean identityHashMap)
public Counter(MapFactory<E,java.lang.Double> mf)
public Counter(java.util.Map<? extends E,java.lang.Double> mapCounts)
public Counter(java.util.Collection<? extends E> collection)
public double getDeflt()
public void setDeflt(double deflt)
public java.util.Set<E> keySet()
public java.util.Set<java.util.Map.Entry<E,java.lang.Double>> entrySet()
public int size()
public boolean isEmpty()
public boolean containsKey(E key)
key
- public double getCount(E key)
key
- public double getProbability(E key)
key
- public void normalize()
public void setCount(E key, double count)
key
- count
- public void put(E key, double count, boolean keepHigher)
key
- count
- public E sample(java.util.Random rand)
public E sample()
public void removeKey(E key)
protected void removeKeyFromEntries(E key)
key
- public void setMaxCount(E key, double val)
key
- val
- public void setMinCount(E key, double val)
key
- val
- public double incrementCount(E key, double increment)
key
- increment
- public void incrementAll(java.util.Collection<? extends E> collection, double count)
public double totalCount()
public java.util.List<E> getSortedKeys()
public E argMax()
public double min()
public double max()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStringSortedByKeys()
public java.lang.String toString(int maxKeysToPrint)
maxKeysToPrint
- public java.lang.String toString(int maxKeysToPrint, boolean multiline)
maxKeysToPrint
- public PriorityQueue<E> asPriorityQueue()
public PriorityQueue<E> asMinPriorityQueue()
public void pruneKeysBelowThreshold(double cutoff)
public java.util.Set<java.util.Map.Entry<E,java.lang.Double>> getEntrySet()
public static void main(java.lang.String[] args)
public void clear()
public void keepTopNKeys(int keepN)
public void keepBottomNKeys(int keepN)
public void setAllCounts(double val)
public void scale(double c)
public void setDirty(boolean dirty)
public java.lang.String toStringTabSeparated()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object