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

java.lang.Object
  extended by edu.stanford.nlp.stats.TwoDimensionalCounter<K1,K2>
All Implemented Interfaces:
Serializable

public class TwoDimensionalCounter<K1,K2>
extends Object
implements 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(TwoDimensionalCounter<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, ClassicCounter<K2> c)
          replace the counter for K1-index o by new counter c
 int size()
           
 void subtractAll(K1 key, Counter<K2> c)
           
 void subtractAll(TwoDimensionalCounter<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)

defaultReturnValue

public double defaultReturnValue()

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)
Returns:
the inner Counter associated with key o

entrySet

public Set<Map.Entry<K1,ClassicCounter<K2>>> entrySet()

size

public int size()
Returns:
total number of entries (key pairs)

containsKey

public boolean containsKey(K1 o1,
                           K2 o2)

incrementCount

public void incrementCount(K1 o1,
                           K2 o2)

incrementCount

public void incrementCount(K1 o1,
                           K2 o2,
                           double count)

decrementCount

public void decrementCount(K1 o1,
                           K2 o2)

decrementCount

public void decrementCount(K1 o1,
                           K2 o2,
                           double count)

setCount

public void setCount(K1 o1,
                     K2 o2,
                     double count)

remove

public double remove(K1 o1,
                     K2 o2)

getCount

public double getCount(K1 o1,
                       K2 o2)

totalCount

public double totalCount()
Takes linear time.


totalCount

public double totalCount(K1 k1)

firstKeySet

public Set<K1> firstKeySet()

setCounter

public ClassicCounter<K2> setCounter(K1 o,
                                     ClassicCounter<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)

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.


toCSVString

public String toCSVString(NumberFormat nf)

secondKeySet

public Set<K2> secondKeySet()

isEmpty

public boolean isEmpty()

flatten

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

addAll

public void addAll(TwoDimensionalCounter<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(TwoDimensionalCounter<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)

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