Package edu.stanford.nlp.stats
Class TwoDimensionalCounter<K1,K2>
- java.lang.Object
-
- edu.stanford.nlp.stats.TwoDimensionalCounter<K1,K2>
-
- All Implemented Interfaces:
TwoDimensionalCounterInterface<K1,K2>,Serializable
public class TwoDimensionalCounter<K1,K2> extends Object implements TwoDimensionalCounterInterface<K1,K2>, Serializable
A class representing a mapping between pairs of typed objects and double values.- Author:
- Teg Grenager
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TwoDimensionalCounter()TwoDimensionalCounter(MapFactory<K1,ClassicCounter<K2>> outerFactory, MapFactory<K2,MutableDouble> innerFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAll(TwoDimensionalCounterInterface<K1,K2> c)voidaddAll(K1 key, Counter<K2> c)voidclean()voidclear()clears the map, total and default valuebooleancontainsFirstKey(K1 o1)booleancontainsKey(K1 o1, K2 o2)voiddecrementCount(K1 o1, K2 o2)voiddecrementCount(K1 o1, K2 o2, double count)doubledefaultReturnValue()voiddefaultReturnValue(double rv)Set<Map.Entry<K1,ClassicCounter<K2>>>entrySet()booleanequals(Object o)Set<K1>firstKeySet()ClassicCounter<Pair<K1,K2>>flatten()doublegetCount(K1 o1, K2 o2)ClassicCounter<K2>getCounter(K1 o)MapFactory<K2,MutableDouble>getInnerMapFactory()MapFactory<K1,ClassicCounter<K2>>getOuterMapFactory()inthashCode()static <K1,K2>
TwoDimensionalCounter<K1,K2>identityHashMapCounter()voidincrementCount(K1 o1, K2 o2)voidincrementCount(K1 o1, K2 o2, double count)booleanisEmpty()static voidmain(String[] args)voidrecomputeTotal()voidremove(K1 key)doubleremove(K1 o1, K2 o2)voidremoveZeroCounts()static <K1,K2>
TwoDimensionalCounter<K2,K1>reverseIndexOrder(TwoDimensionalCounter<K1,K2> cc)Produces a new ConditionalCounter.Set<K2>secondKeySet()voidsetCount(K1 o1, K2 o2, double count)ClassicCounter<K2>setCounter(K1 o, Counter<K2> c)replace the counter for K1-index o by new counter cintsize()intsizeOuterMap()voidsubtractAll(TwoDimensionalCounterInterface<K1,K2> c, boolean removeKeys)voidsubtractAll(K1 key, Counter<K2> c)Counter<K1>sumInnerCounter()Returns the counters with keys as the first key and count as the total count of the inner counter for that keyStringtoCSVString(NumberFormat nf)double[][]toMatrix(List<K1> firstKeys, List<K2> secondKeys)Given an ordering of the first (row) and second (column) keys, will produce a double matrix.StringtoMatrixString(int cellSize)StringtoMatrixString(int cellSize, NumberFormat nf)StringtoString()A simple String representation of this TwoDimensionalCounter, which has the String representation of each key pair on a separate line, followed by the count for that pair.doubletotalCount()Takes linear time.doubletotalCount(K1 k1)
-
-
-
Constructor Detail
-
TwoDimensionalCounter
public TwoDimensionalCounter()
-
TwoDimensionalCounter
public TwoDimensionalCounter(MapFactory<K1,ClassicCounter<K2>> outerFactory, MapFactory<K2,MutableDouble> innerFactory)
-
-
Method Detail
-
defaultReturnValue
public void defaultReturnValue(double rv)
- Specified by:
defaultReturnValuein interfaceTwoDimensionalCounterInterface<K1,K2>
-
defaultReturnValue
public double defaultReturnValue()
- Specified by:
defaultReturnValuein interfaceTwoDimensionalCounterInterface<K1,K2>
-
getCounter
public ClassicCounter<K2> getCounter(K1 o)
- Specified by:
getCounterin interfaceTwoDimensionalCounterInterface<K1,K2>- Returns:
- the inner Counter associated with key o
-
entrySet
public Set<Map.Entry<K1,ClassicCounter<K2>>> entrySet()
-
size
public int size()
- Specified by:
sizein interfaceTwoDimensionalCounterInterface<K1,K2>- Returns:
- total number of entries (key pairs)
-
sizeOuterMap
public int sizeOuterMap()
- Returns:
- size of the outer map
-
containsKey
public boolean containsKey(K1 o1, K2 o2)
- Specified by:
containsKeyin interfaceTwoDimensionalCounterInterface<K1,K2>
-
containsFirstKey
public boolean containsFirstKey(K1 o1)
-
incrementCount
public void incrementCount(K1 o1, K2 o2)
- Specified by:
incrementCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
incrementCount
public void incrementCount(K1 o1, K2 o2, double count)
- Specified by:
incrementCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
decrementCount
public void decrementCount(K1 o1, K2 o2)
- Specified by:
decrementCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
decrementCount
public void decrementCount(K1 o1, K2 o2, double count)
- Specified by:
decrementCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
setCount
public void setCount(K1 o1, K2 o2, double count)
- Specified by:
setCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
remove
public double remove(K1 o1, K2 o2)
- Specified by:
removein interfaceTwoDimensionalCounterInterface<K1,K2>
-
getCount
public double getCount(K1 o1, K2 o2)
- Specified by:
getCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
totalCount
public double totalCount()
Takes linear time.- Specified by:
totalCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
totalCount
public double totalCount(K1 k1)
- Specified by:
totalCountin interfaceTwoDimensionalCounterInterface<K1,K2>
-
firstKeySet
public Set<K1> firstKeySet()
- Specified by:
firstKeySetin interfaceTwoDimensionalCounterInterface<K1,K2>
-
setCounter
public ClassicCounter<K2> setCounter(K1 o, Counter<K2> c)
replace the counter for K1-index o by new counter c
-
reverseIndexOrder
public static <K1,K2> TwoDimensionalCounter<K2,K1> reverseIndexOrder(TwoDimensionalCounter<K1,K2> cc)
Produces a new ConditionalCounter.- Returns:
- a new ConditionalCounter, where order of indices is reversed
-
toString
public String toString()
A simple String representation of this TwoDimensionalCounter, which has the String representation of each key pair on a separate line, followed by the count for that pair. The items are tab separated, so the result is a tab-separated value (TSV) file. Iff none of the keys contain spaces, it will also be possible to treat this as whitespace separated fields.
-
toMatrixString
public String toMatrixString(int cellSize)
- Specified by:
toMatrixStringin interfaceTwoDimensionalCounterInterface<K1,K2>
-
toMatrixString
public String toMatrixString(int cellSize, NumberFormat nf)
-
toMatrix
public double[][] toMatrix(List<K1> firstKeys, List<K2> secondKeys)
Given an ordering of the first (row) and second (column) keys, will produce a double matrix.- Specified by:
toMatrixin interfaceTwoDimensionalCounterInterface<K1,K2>
-
toCSVString
public String toCSVString(NumberFormat nf)
- Specified by:
toCSVStringin interfaceTwoDimensionalCounterInterface<K1,K2>
-
secondKeySet
public Set<K2> secondKeySet()
- Specified by:
secondKeySetin interfaceTwoDimensionalCounterInterface<K1,K2>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceTwoDimensionalCounterInterface<K1,K2>
-
flatten
public ClassicCounter<Pair<K1,K2>> flatten()
-
addAll
public void addAll(TwoDimensionalCounterInterface<K1,K2> c)
-
subtractAll
public void subtractAll(TwoDimensionalCounterInterface<K1,K2> c, boolean removeKeys)
-
sumInnerCounter
public Counter<K1> sumInnerCounter()
Returns the counters with keys as the first key and count as the total count of the inner counter for that key- Returns:
- counter of type K1
-
removeZeroCounts
public void removeZeroCounts()
-
remove
public void remove(K1 key)
- Specified by:
removein interfaceTwoDimensionalCounterInterface<K1,K2>
-
clear
public void clear()
clears the map, total and default value
-
clean
public void clean()
-
getOuterMapFactory
public MapFactory<K1,ClassicCounter<K2>> getOuterMapFactory()
-
getInnerMapFactory
public MapFactory<K2,MutableDouble> getInnerMapFactory()
-
identityHashMapCounter
public static <K1,K2> TwoDimensionalCounter<K1,K2> identityHashMapCounter()
-
recomputeTotal
public void recomputeTotal()
-
main
public static void main(String[] args)
-
-