public class GeneralizedCounter<K>
extends java.lang.Object
implements java.io.Serializable
Lists of a
prespecified length. A depth n GeneralizedCounter can be
thought of as a conditionalized count over n classes of
objects, in a prespecified order. Also offers a read-only view as
a Counter. This class is serializable but no guarantees are made about compatibility version to version.
This is the worst class. Use TwoDimensionalCounter. If you need a third, write ThreeDimensionalCounter, but don't use this.| Constructor and Description |
|---|
GeneralizedCounter(int depth)
Constructs a new GeneralizedCounter of a specified depth
|
| Modifier and Type | Method and Description |
|---|---|
GeneralizedCounter<K> |
conditionalize(java.util.List<K> l)
returns a GeneralizedCounter conditioned on the objects in the
List argument. |
GeneralizedCounter<K> |
conditionalizeOnce(K o)
Returns a GeneralizedCounter conditioned on the given top level object.
|
boolean |
containsKey(java.util.List<K> key)
Like
ClassicCounter, this currently returns true if the count is
explicitly 0.0 for something |
ClassicCounter<java.util.List<K>> |
counterView()
Returns a read-only synchronous view (not a snapshot) of
this as a ClassicCounter. |
int |
depth()
Returns the depth of the GeneralizedCounter (i.e., the dimension
of the distribution).
|
java.util.Set<java.util.Map.Entry<java.util.List<K>,java.lang.Double>> |
entrySet()
Returns the set of entries in the GeneralizedCounter.
|
double |
getCount(K o1,
K o2)
A convenience method equivalent to
; works only for depth 2
GeneralizedCounters |
double |
getCount(K o1,
K o2,
K o3)
A convenience method equivalent to
; works only for depth 3
GeneralizedCounters |
double |
getCount(java.lang.Object o)
Equivalent to
; works only
for depth 1 GeneralizedCounters |
double[] |
getCounts(java.util.List<K> l)
returns a
double[] array of length
depth+1, containing the conditional counts on a
depth-length list given each level of conditional
distribution from 0 to depth. |
void |
incrementCount(java.util.List<K> l)
Equivalent to incrementCount(l, 1.0).
|
void |
incrementCount(java.util.List<K> l,
double count)
adds to count for the
depth()-dimensional key l. |
void |
incrementCount(java.util.List<K> l,
K o)
equivalent to incrementCount(l,o,1.0).
|
void |
incrementCount(java.util.List<K> l,
K o,
double count)
same as incrementCount(List, double) but as if Object o were at the end of the list
|
void |
incrementCount1D(K o)
Equivalent to incrementCount1D(o, 1.0).
|
void |
incrementCount1D(K o,
double count)
Equivalent to
;
only works for a depth 1 GeneralizedCounter. |
void |
incrementCount2D(K first,
K second)
Equivalent to incrementCount2D(first,second,1.0).
|
void |
incrementCount2D(K first,
K second,
double count)
Equivalent to incrementCount( new Object[] { first, second }, count ).
|
void |
incrementCount3D(K first,
K second,
K third)
Equivalent to incrementCount3D(first,second,1.0).
|
void |
incrementCount3D(K first,
K second,
K third,
double count)
Equivalent to incrementCount( new Object[] { first, second, third }, count ).
|
boolean |
isEmpty()
Returns true if nothing has a count.
|
java.util.Set<java.util.List<K>> |
keySet()
Returns the set of keys, as read-only
Lists of size
equal to the depth of the GeneralizedCounter. |
java.util.Set<java.util.Map.Entry<java.util.List<K>,ClassicCounter<K>>> |
lowestLevelCounterEntrySet()
Returns a set of entries, where each key is a read-only
List of size one less than the depth of the GeneralizedCounter, and
each value is a ClassicCounter. |
static void |
main(java.lang.String[] args)
for testing purposes only
|
ClassicCounter<K> |
oneDimensionalCounterView()
Returns a read-only synchronous view (not a snapshot) of
this as a ClassicCounter. |
void |
prettyPrint()
pretty-prints the GeneralizedCounter to
System.out. |
void |
prettyPrint(java.io.PrintWriter pw)
pretty-prints the GeneralizedCounter, using a buffer increment of two spaces.
|
void |
prettyPrint(java.io.PrintWriter pw,
java.lang.String bufferIncrement)
pretty-prints the GeneralizedCounter.
|
GeneralizedCounter<K> |
reverseKeys() |
java.util.Set<K> |
topLevelKeySet()
Returns the set of elements that occur in the 0th position of a
List key in the GeneralizedCounter. |
java.lang.String |
toString() |
java.lang.String |
toString(java.lang.String param) |
double |
totalCount()
returns the total count of objects in the GeneralizedCounter.
|
public GeneralizedCounter(int depth)
depth - the depth of the GeneralizedCounterpublic java.util.Set<java.util.Map.Entry<java.util.List<K>,java.lang.Double>> entrySet()
List of size equal to the depth of the GeneralizedCounter, and
each value is a Double. Each entry is a Map.Entry object,
but these objects
do not support the Map.Entry.setValue(V) method; attempts to call
that method with result
in an UnsupportedOperationException being thrown.public java.util.Set<java.util.Map.Entry<java.util.List<K>,ClassicCounter<K>>> lowestLevelCounterEntrySet()
List of size one less than the depth of the GeneralizedCounter, and
each value is a ClassicCounter. Each entry is a Map.Entry object, but these objects
do not support the Map.Entry.setValue(V) method; attempts to call that method with result
in an UnsupportedOperationException being thrown.public double totalCount()
public java.util.Set<K> topLevelKeySet()
List key in the GeneralizedCounter.conditionalize(List),
getCount(java.lang.Object)public java.util.Set<java.util.List<K>> keySet()
Lists of size
equal to the depth of the GeneralizedCounter.public int depth()
public boolean isEmpty()
public double getCount(java.lang.Object o)
getCounts(java.util.List<K>)({o}); works only
for depth 1 GeneralizedCounterspublic double getCount(K o1, K o2)
getCounts(java.util.List<K>)({o1,o2}); works only for depth 2
GeneralizedCounterspublic double getCount(K o1, K o2, K o3)
getCounts(java.util.List<K>)({o1,o2,o3}); works only for depth 3
GeneralizedCounterspublic double[] getCounts(java.util.List<K> l)
double[] array of length
depth+1, containing the conditional counts on a
depth-length list given each level of conditional
distribution from 0 to depth.public GeneralizedCounter<K> conditionalize(java.util.List<K> l)
List argument. The length of the argument List
must be less than the depth of the GeneralizedCounter.public GeneralizedCounter<K> conditionalizeOnce(K o)
conditionalize(new Object[] { o }).public void incrementCount(java.util.List<K> l, K o)
public void incrementCount(java.util.List<K> l, K o, double count)
public void incrementCount(java.util.List<K> l)
public void incrementCount(java.util.List<K> l, double count)
depth()-dimensional key l.public void incrementCount2D(K first, K second)
public void incrementCount2D(K first, K second, double count)
public void incrementCount3D(K first, K second, K third)
public void incrementCount3D(K first, K second, K third, double count)
public void incrementCount1D(K o)
public void incrementCount1D(K o, double count)
incrementCount(java.util.List<K>, K)({o}, count);
only works for a depth 1 GeneralizedCounter.public boolean containsKey(java.util.List<K> key)
ClassicCounter, this currently returns true if the count is
explicitly 0.0 for somethingpublic GeneralizedCounter<K> reverseKeys()
public ClassicCounter<java.util.List<K>> counterView()
this as a ClassicCounter. Any calls to
count-changing or entry-removing operations will result in an
UnsupportedOperationException. At some point in the
future, this view may gain limited writable functionality.public ClassicCounter<K> oneDimensionalCounterView()
this as a ClassicCounter. Works only with one-dimensional
GeneralizedCounters. Exactly like counterView(), except
that getCount(java.lang.Object) operates on primitive objects of the counter instead
of singleton lists. Any calls to
count-changing or entry-removing operations will result in an
UnsupportedOperationException. At some point in the
future, this view may gain limited writable functionality.public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toString(java.lang.String param)
public static void main(java.lang.String[] args)
public void prettyPrint()
System.out.public void prettyPrint(java.io.PrintWriter pw)
public void prettyPrint(java.io.PrintWriter pw,
java.lang.String bufferIncrement)