edu.stanford.nlp.stats
Class TwoDimensionalCounter<K1,K2>

java.lang.Object
  extended by 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
TwoDimensionalCounter()
           
TwoDimensionalCounter(MapFactory<K1,ClassicCounter<K2>> outerFactory, MapFactory<K2,MutableDouble> innerFactory)
           
 
Method Summary
 void addAll(K1 key, Counter<K2> c)
           
 void addAll(TwoDimensionalCounterInterface<K1,K2> c)
           
 void clean()
           
 boolean containsKey(K1 o1, K2 o2)
           
 void decrementCount(K1 o1, K2 o2)
           
 void decrementCount(K1 o1, K2 o2, double count)
           
 double defaultReturnValue()
           
 void defaultReturnValue(double rv)
           
 Set<Map.Entry<K1,ClassicCounter<K2>>> entrySet()
           
 boolean equals(Object o)
           
 Set<K1> firstKeySet()
           
 ClassicCounter<Pair<K1,K2>> flatten()
           
 double getCount(K1 o1, K2 o2)
           
 ClassicCounter<K2> getCounter(K1 o)
           
 MapFactory<K2,MutableDouble> getInnerMapFactory()
           
 MapFactory<K1,ClassicCounter<K2>> getOuterMapFactory()
           
 int hashCode()
           
 void incrementCount(K1 o1, K2 o2)
           
 void incrementCount(K1 o1, K2 o2, double count)
           
 boolean isEmpty()
           
static void main(String[] args)
           
 void remove(K1 key)
           
 double remove(K1 o1, K2 o2)
           
 void removeZeroCounts()
           
static
<K1,K2> TwoDimensionalCounter<K2,K1>
reverseIndexOrder(TwoDimensionalCounter<K1,K2> cc)
          Produces a new ConditionalCounter.
 Set<K2> secondKeySet()
           
 void setCount(K1 o1, K2 o2, double count)
           
 ClassicCounter<K2> setCounter(K1 o, Counter<K2> c)
          replace the counter for K1-index o by new counter c
 int size()
           
 void subtractAll(K1 key, Counter<K2> c)
           
 void subtractAll(TwoDimensionalCounterInterface<K1,K2> c, boolean removeKeys)
           
 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
 String toCSVString(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.
 String toMatrixString(int cellSize)
           
 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.
 double totalCount()
          Takes linear time.
 double totalCount(K1 k1)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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:
defaultReturnValue in interface TwoDimensionalCounterInterface<K1,K2>

defaultReturnValue

public double defaultReturnValue()
Specified by:
defaultReturnValue in interface TwoDimensionalCounterInterface<K1,K2>

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getCounter

public ClassicCounter<K2> getCounter(K1 o)
Specified by:
getCounter in interface TwoDimensionalCounterInterface<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:
size in interface TwoDimensionalCounterInterface<K1,K2>
Returns:
total number of entries (key pairs)

containsKey

public boolean containsKey(K1 o1,
                           K2 o2)
Specified by:
containsKey in interface TwoDimensionalCounterInterface<K1,K2>

incrementCount

public void incrementCount(K1 o1,
                           K2 o2)
Specified by:
incrementCount in interface TwoDimensionalCounterInterface<K1,K2>

incrementCount

public void incrementCount(K1 o1,
                           K2 o2,
                           double count)
Specified by:
incrementCount in interface TwoDimensionalCounterInterface<K1,K2>

decrementCount

public void decrementCount(K1 o1,
                           K2 o2)
Specified by:
decrementCount in interface TwoDimensionalCounterInterface<K1,K2>

decrementCount

public void decrementCount(K1 o1,
                           K2 o2,
                           double count)
Specified by:
decrementCount in interface TwoDimensionalCounterInterface<K1,K2>

setCount

public void setCount(K1 o1,
                     K2 o2,
                     double count)
Specified by:
setCount in interface TwoDimensionalCounterInterface<K1,K2>

remove

public double remove(K1 o1,
                     K2 o2)
Specified by:
remove in interface TwoDimensionalCounterInterface<K1,K2>

getCount

public double getCount(K1 o1,
                       K2 o2)
Specified by:
getCount in interface TwoDimensionalCounterInterface<K1,K2>

totalCount

public double totalCount()
Takes linear time.

Specified by:
totalCount in interface TwoDimensionalCounterInterface<K1,K2>

totalCount

public double totalCount(K1 k1)
Specified by:
totalCount in interface TwoDimensionalCounterInterface<K1,K2>

firstKeySet

public Set<K1> firstKeySet()
Specified by:
firstKeySet in interface TwoDimensionalCounterInterface<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.

Overrides:
toString in class Object

toMatrixString

public String toMatrixString(int cellSize)
Specified by:
toMatrixString in interface TwoDimensionalCounterInterface<K1,K2>

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:
toMatrix in interface TwoDimensionalCounterInterface<K1,K2>

toCSVString

public String toCSVString(NumberFormat nf)
Specified by:
toCSVString in interface TwoDimensionalCounterInterface<K1,K2>

secondKeySet

public Set<K2> secondKeySet()
Specified by:
secondKeySet in interface TwoDimensionalCounterInterface<K1,K2>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface TwoDimensionalCounterInterface<K1,K2>

flatten

public ClassicCounter<Pair<K1,K2>> flatten()

addAll

public void addAll(TwoDimensionalCounterInterface<K1,K2> c)

addAll

public void addAll(K1 key,
                   Counter<K2> c)

subtractAll

public void subtractAll(K1 key,
                        Counter<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:
remove in interface TwoDimensionalCounterInterface<K1,K2>

clean

public void clean()

getOuterMapFactory

public MapFactory<K1,ClassicCounter<K2>> getOuterMapFactory()

getInnerMapFactory

public MapFactory<K2,MutableDouble> getInnerMapFactory()

main

public static void main(String[] args)


Stanford NLP Group