|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.stats.Counters
public class Counters
Static methods for operating on Counter
s.
Method Summary | ||
---|---|---|
static
|
absoluteDifference(Counter<E> c1,
Counter<E> c2)
Returns |c1 - c2|. |
|
static
|
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
|
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
|
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
|
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
|
argmax(Counter<E> c)
Finds and returns the key in this Counter with the largest count. |
|
static
|
argmin(Counter<E> c)
Finds and returns the key in this Counter with the largest count. |
|
static
|
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
|
asMap(Counter<E> counter)
Returns a map view of the given counter. |
|
static
|
average(Counter<E> c1,
Counter<E> c2)
Returns a new Counter with counts averaged from the two given Counters. |
|
static
|
cosine(Counter<E> c1,
Counter<E> c2)
|
|
static
|
crossEntropy(Counter<E> from,
Counter<E> to)
Note that this implementation doesn't normalize the "from" Counter. |
|
static ClassicCounter |
deserializeCounter(String filename)
|
|
static
|
diff(Counter<T> goldFeatures,
Counter<T> guessedFeatures)
|
|
static
|
divideInPlace(Counter<E> target,
Counter<E> denominator)
Divides every non-zero count in target by the corresponding value in the denominator Counter. |
|
static
|
division(Counter<E> c1,
Counter<E> c2)
Returns c1 divided by c2. |
|
static
|
dotProduct(Counter<E> c1,
Counter<E> c2)
Returns the product of c1 and c2. |
|
static
|
entropy(Counter<E> c)
Calculates the entropy of the given counter (in bits). |
|
static
|
equals(Counter<E> o1,
Counter<E> o2)
Default equality comparison for two counters potentially backed by alternative implementations. |
|
static
|
exp(Counter<T> c)
|
|
static
|
expInPlace(Counter<T> c)
|
|
static
|
fromMap(Map<E,N> map)
Returns a counter view of the given map. |
|
static
|
fromMap(Map<E,N> map,
Class<N> type)
Returns a counter view of the given map. |
|
static
|
getCountCounts(Counter<E> c)
|
|
static
|
intersection(Counter<E> c1,
Counter<E> c2)
Returns a counter that is the intersection of c1 and c2. |
|
static
|
jaccardCoefficient(Counter<E> c1,
Counter<E> c2)
Returns the Jaccard Coefficient of the two counters. |
|
static
|
jensenShannonDivergence(Counter<E> c1,
Counter<E> c2)
Calculates the Jensen-Shannon divergence between the two counters. |
|
static
|
keysAbove(Counter<E> c,
double countThreshold)
Returns the set of keys whose counts are at or above the given threshold. |
|
static
|
keysAt(Counter<E> c,
double count)
Returns the set of keys that have exactly the given count. |
|
static
|
keysBelow(Counter<E> c,
double countThreshold)
Returns the set of keys whose counts are at or below the given threshold. |
|
static
|
klDivergence(Counter<E> from,
Counter<E> to)
Calculates the KL divergence between the two counters. |
|
static
|
L2Normalize(C c)
L2 normalize a counter. |
|
static
|
linearCombination(Counter<E> c1,
double w1,
Counter<E> c2,
double w2)
Returns a Counter which is a weighted average of c1 and c2. |
|
static
|
load2DCounter(String filename,
Class<T1> t1,
Class<T2> t2)
|
|
static
|
loadCounter(String filename,
Class<E> c)
Loads a Counter from a text file. |
|
static
|
loadIntCounter(String filename,
Class<E> c)
Loads a Counter from a text file. |
|
static
|
logInPlace(Counter<E> target)
|
|
static
|
logNormalize(Counter<E> c)
|
|
static
|
logSum(Counter<E> c)
Returns ArrayMath.logSum of the values in this counter |
|
static
|
max(Counter<E> c)
Returns the value of the maximum entry in this counter. |
|
static
|
mean(Counter<E> c)
Returns the mean of all the counts (totalCount/size). |
|
static
|
min(Counter<E> c)
Returns the value of the smallest entry in this counter. |
|
static
|
multiplyInPlace(Counter<E> target,
Counter<E> term)
Multiplies every count in target by the corresponding value in the term Counter. |
|
static
|
normalize(Counter<E> target)
Normalizes the target counter in-place, so the sum of the resulting values equals 1. |
|
static
|
perturbCounts(C c,
Random random,
double p)
|
|
static
|
pow(Counter<T> c,
double temp)
|
|
static
|
powInPlace(Counter<T> c,
double temp)
|
|
static
|
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
|
printCounterComparison(Counter<E> a,
Counter<E> b)
Great for debugging. |
|
static
|
printCounterComparison(Counter<E> a,
Counter<E> b,
PrintStream out)
Great for debugging. |
|
static
|
printCounterSortedByKeys(Counter<E> c)
|
|
static
|
product(Counter<E> c1,
Counter<E> c2)
Returns the product of c1 and c2. |
|
static
|
restrictedArgMax(Counter<E> c,
Collection<E> restriction)
|
|
static
|
retainNonZeros(Counter<E> counter)
Removes all entries with 0 count in the counter, returning the set of removed entries. |
|
static
|
retainTop(Counter<E> c,
int num)
Removes all entries from c except for the top num |
|
static
|
sample(Counter<T> c)
Does not assumes c is normalized. |
|
static
|
sample(Counter<T> c,
Random rand)
Does not assumes c is normalized. |
|
static
|
save2DCounter(TwoDimensionalCounter<T1,T2> tdc,
String filename)
|
|
static
|
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
|
saveCounter(Counter<E> c,
String filename)
Saves a Counter to a text file. |
|
static
|
scale(C c,
double s)
Returns a new Counter which is scaled by the given scale factor. |
|
static
|
scale(TwoDimensionalCounter<T1,T2> c,
double d)
Creates a new TwoDimensionalCounter where all the counts are scaled by d. |
|
static
|
scaleInPlace(Counter<E> target,
double scale)
Multiplies each value in target by scale, in place. |
|
static void |
serializeCounter(Counter c,
String filename)
|
|
static
|
skewDivergence(Counter<E> c1,
Counter<E> c2,
double skew)
Calculates the skew divergence between the two counters. |
|
static
|
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
|
toBiggestValuesFirstString(Counter<E> c)
|
|
static
|
toBiggestValuesFirstString(Counter<E> c,
int k)
|
|
static
|
toBiggestValuesFirstString(Counter<Integer> c,
int k,
Index<T> index)
|
|
static
|
toComparator(Counter<E> counter)
Returns a comparator backed by this counter: two objects are compared by their associated values stored in the counter. |
|
static
|
toComparatorDescending(Counter<E> counter)
|
|
static
|
toCounter(double[] counts,
Index<T> index)
|
|
static
|
toCounter(Map<Integer,? extends Number> counts,
Index<E> index)
Turns the given map and index into a counter instance. |
|
static
|
toPriorityQueue(Counter<E> c)
Returns a PriorityQueue of the c where the score of the object is its priority. |
|
static
|
toSortedList(Counter<E> c)
A List of the keys in c, sorted from highest count to lowest. |
|
static
|
toString(Counter<E> counter,
NumberFormat nf)
|
|
static
|
toVerticalString(Counter<E> c)
|
|
static
|
toVerticalString(Counter<E> c,
int k)
|
|
static
|
toVerticalString(Counter<E> c,
int k,
String fmt)
|
|
static
|
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
|
toVerticalString(Counter<E> c,
String fmt)
|
|
static
|
transform(Counter<T1> c,
Function<T1,T2> f)
Returns the counter with keys modified according to function F. |
|
static
|
union(C c1,
C c2)
Returns a Counter that is the union of the two Counters passed in (counts are added). |
|
static
|
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 |
---|
public static <E> double logSum(Counter<E> c)
public static <E> void logNormalize(Counter<E> c)
public static <E> double max(Counter<E> c)
public static <E> double min(Counter<E> c)
public static <E> E argmax(Counter<E> c)
public static <E> E argmin(Counter<E> c)
public static <E> double mean(Counter<E> c)
public static <E> void addInPlace(Counter<E> target, Counter<E> arg, double scale)
public static <E> void addInPlace(Counter<E> target, Counter<E> arg)
public static <T1,T2> void addInPlace(TwoDimensionalCounter<T1,T2> target, TwoDimensionalCounter<T1,T2> arg, double scale)
T1
- T2
- target
- arg
- scale
- public static <T1,T2> void addInPlace(TwoDimensionalCounter<T1,T2> target, TwoDimensionalCounter<T1,T2> arg)
T1
- T2
- target
- arg
- public static <E> void subtractInPlace(Counter<E> target, Counter<E> arg)
public static <E> void divideInPlace(Counter<E> target, Counter<E> denominator)
public static <E> void multiplyInPlace(Counter<E> target, Counter<E> term)
public static <E> void scaleInPlace(Counter<E> target, double scale)
public static <E> void normalize(Counter<E> target)
E
- target
- public static <E> void logInPlace(Counter<E> target)
public static <E> void retainTop(Counter<E> c, int num)
num
public static <E> Set<E> retainNonZeros(Counter<E> counter)
public static <E> Set<E> keysAbove(Counter<E> c, double countThreshold)
public static <E> Set<E> keysBelow(Counter<E> c, double countThreshold)
public static <E> Set<E> keysAt(Counter<E> c, double count)
public static <T1,T2> Counter<T2> transform(Counter<T1> c, Function<T1,T2> f)
public static <E> Comparator<E> toComparator(Counter<E> counter)
public static <E> Comparator<E> toComparatorDescending(Counter<E> counter)
public static <E> List<E> toSortedList(Counter<E> c)
c
-
public static <E> PriorityQueue<E> toPriorityQueue(Counter<E> c)
PriorityQueue
of the c where the score of the object is its priority.
public static <E,C extends Counter<E>> C union(C c1, C c2)
c1
- c2
-
public static <E> Counter<E> intersection(Counter<E> c1, Counter<E> c2)
c1
- c2
-
public static <E> double jaccardCoefficient(Counter<E> c1, Counter<E> c2)
c1
- c2
-
public static <E> Counter<E> product(Counter<E> c1, Counter<E> c2)
c1
- c2
-
public static <E> double dotProduct(Counter<E> c1, Counter<E> c2)
c1
- c2
-
public static <E> Counter<E> absoluteDifference(Counter<E> c1, Counter<E> c2)
c1
- c2
-
public static <E> Counter<E> division(Counter<E> c1, Counter<E> c2)
c1
- c2
-
public static <E> double entropy(Counter<E> c)
public static <E> double crossEntropy(Counter<E> from, Counter<E> to)
public static <E> double klDivergence(Counter<E> from, Counter<E> to)
from
- to
-
public static <E> double jensenShannonDivergence(Counter<E> c1, Counter<E> c2)
c1
- c2
-
public static <E> double skewDivergence(Counter<E> c1, Counter<E> c2, double skew)
c1
- c2
- skew
-
public static <E,C extends Counter<E>> C L2Normalize(C c)
c
- the Counter
to be L2 normalized.public static <E> double cosine(Counter<E> c1, Counter<E> c2)
public static <E> Counter<E> average(Counter<E> c1, Counter<E> c2)
public static <E> Counter<E> linearCombination(Counter<E> c1, double w1, Counter<E> c2, double w2)
public static <E,C extends Counter<E>> C perturbCounts(C c, Random random, double p)
public static <E> void printCounterComparison(Counter<E> a, Counter<E> b)
a
- b
- public static <E> void printCounterComparison(Counter<E> a, Counter<E> b, PrintStream out)
a
- b
- public static <E> Counter<Double> getCountCounts(Counter<E> c)
public static <E,C extends Counter<E>> C scale(C c, double s)
public static <E extends Comparable<E>> void printCounterSortedByKeys(Counter<E> c)
public static <E> ClassicCounter<E> loadCounter(String filename, Class<E> c) throws RuntimeException
filename
- the path to the file to load the Counter fromc
- the Class to instantiate each member of the set. Must have a String constructor.
RuntimeException
public static <E> IntCounter<E> loadIntCounter(String filename, Class<E> c) throws Exception
filename
- the path to the file to load the Counter fromc
- the Class to instantiate each member of the set. Must have a String constructor.
Exception
public static <E> void saveCounter(Counter<E> c, OutputStream stream)
public static <E> void saveCounter(Counter<E> c, String filename) throws IOException
IOException
public static <T1,T2> TwoDimensionalCounter<T1,T2> load2DCounter(String filename, Class<T1> t1, Class<T2> t2) throws RuntimeException
RuntimeException
public static <T1,T2> void save2DCounter(TwoDimensionalCounter<T1,T2> tdc, String filename) throws IOException
IOException
public static void serializeCounter(Counter c, String filename) throws IOException
IOException
public static ClassicCounter deserializeCounter(String filename) throws Exception
Exception
public static <E> String toString(Counter<E> counter, NumberFormat nf)
public static <E> String toBiggestValuesFirstString(Counter<E> c)
public static <E> String toBiggestValuesFirstString(Counter<E> c, int k)
public static <T> String toBiggestValuesFirstString(Counter<Integer> c, int k, Index<T> index)
public static <E> String toVerticalString(Counter<E> c)
public static <E> String toVerticalString(Counter<E> c, int k)
public static <E> String toVerticalString(Counter<E> c, String fmt)
public static <E> String toVerticalString(Counter<E> c, int k, String fmt)
public static <E> String toVerticalString(Counter<E> c, int k, String fmt, boolean swap)
String
representation of the k
keys
with the largest counts in the given Counter
, using the given
format string.
c
- a Counterk
- how many keys to printfmt
- a format string, such as "%.0f\t%s" (do not include final "%n")swap
- whether the count should appear after the keypublic static <E> E restrictedArgMax(Counter<E> c, Collection<E> restriction)
c
- restriction
-
public static <T> Counter<T> toCounter(double[] counts, Index<T> index)
public static <E> Counter<E> toCounter(Map<Integer,? extends Number> counts, Index<E> index)
public static <T1,T2> TwoDimensionalCounter<T1,T2> scale(TwoDimensionalCounter<T1,T2> c, double d)
c
- d
-
public static <T> T sample(Counter<T> c, Random rand)
c
- rand
-
public static <T> T sample(Counter<T> c)
c
-
public static <E> Counter<E> powNormalized(Counter<E> c, double temp)
public static <T> Counter<T> pow(Counter<T> c, double temp)
public static <T> void powInPlace(Counter<T> c, double temp)
public static <T> Counter<T> exp(Counter<T> c)
public static <T> void expInPlace(Counter<T> c)
public static <T> Counter<T> diff(Counter<T> goldFeatures, Counter<T> guessedFeatures)
public static <E> boolean equals(Counter<E> o1, Counter<E> o2)
public static <T> Counter<T> unmodifiableCounter(Counter<T> counter)
counter
- The counter
public static <E> Counter<E> asCounter(FixedPrioritiesPriorityQueue<E> p)
public static <E,N extends Number> Counter<E> fromMap(Map<E,N> map)
public static <E,N extends Number> Counter<E> fromMap(Map<E,N> map, Class<N> type)
public static <E> Map<E,Double> asMap(Counter<E> counter)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |