|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.berkeley.nlp.lm.collections.Counter<E>
public class Counter<E>
A map from objects to doubles. Includes convenience methods for getting, setting, and incrementing element counts. Objects not in the counter will return a count of zero. The counter is backed by a HashMap .(unless specified otherwise with the MapFactory constructor).
Nested Class Summary | |
---|---|
class |
Counter.EntryValueComparator
|
Constructor Summary | |
---|---|
Counter()
|
|
Counter(Collection<? extends E> collection)
|
|
Counter(Counter<? extends E> counter)
|
Method Summary | ||
---|---|---|
static
|
absCounts(Counter<L> counts)
|
|
boolean |
approxEquals(Counter<E> other,
double tol)
|
|
E |
argMax()
Finds the key with maximum count. |
|
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)
|
|
Set<Map.Entry<E,Double>> |
entrySet()
|
|
double |
getCount(E key)
Get the count of the element, or zero if the element is not in the counter. |
|
double |
getDefaultCount()
|
|
Collection<Map.Entry<E,Double>> |
getEntriesSortedByDecreasingCount()
|
|
Collection<Map.Entry<E,Double>> |
getEntriesSortedByIncreasingCount()
|
|
Set<Map.Entry<E,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. |
|
void |
incrementAll(Collection<? extends E> collection,
double count)
Increment each element in a given collection by a given amount. |
|
|
incrementAll(Counter<T> counter)
|
|
|
incrementAll(Counter<T> counter,
double scale)
|
|
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)
|
|
Set<E> |
keySet()
The elements in the counter. |
|
static void |
main(String[] args)
|
|
double |
max()
|
|
double |
min()
|
|
void |
normalize()
Destructively normalize this Counter in place. |
|
void |
prune(Set<E> toRemove)
|
|
void |
pruneExcept(Set<E> toKeep)
|
|
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 |
putAll(double d)
|
|
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(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 |
setDefaultCount(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()
|
|
String |
toString()
Returns a string representation with the keys ordered by decreasing counts. |
|
String |
toStringSortedByKeys()
|
|
double |
totalCount()
Finds the total of all counts in the counter. |
|
Iterable<Double> |
values()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Counter()
public Counter(Counter<? extends E> counter)
public Counter(Collection<? extends E> collection)
Method Detail |
---|
public double getDefaultCount()
public void setDefaultCount(double deflt)
public Set<E> keySet()
public Set<Map.Entry<E,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(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(Collection<? extends E> collection, double count)
public <T extends E> void incrementAll(Counter<T> counter)
public <T extends E> void incrementAll(Counter<T> counter, double scale)
public double totalCount()
public Collection<Map.Entry<E,Double>> getEntriesSortedByIncreasingCount()
public Collection<Map.Entry<E,Double>> getEntriesSortedByDecreasingCount()
public E argMax()
public double min()
public double max()
public String toString()
toString
in class Object
public String toStringSortedByKeys()
public void pruneKeysBelowThreshold(double cutoff)
public Set<Map.Entry<E,Double>> getEntrySet()
public boolean isEqualTo(Counter<E> counter)
public static void main(String[] args)
public void clear()
public void setAllCounts(double val)
public double dotProduct(Counter<E> other)
public void scale(double c)
public Counter<E> scaledClone(double c)
public Counter<E> difference(Counter<E> counter)
public Counter<E> toLogSpace()
public boolean approxEquals(Counter<E> other, double tol)
public void setDirty(boolean dirty)
public Iterable<Double> values()
public void prune(Set<E> toRemove)
public void pruneExcept(Set<E> toKeep)
public static <L> Counter<L> absCounts(Counter<L> counts)
public void putAll(double d)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |