common
Class SamplingMultiset

java.lang.Object
  extended by common.SamplingMultiset
All Implemented Interfaces:
SetWithDistrib

public class SamplingMultiset
extends java.lang.Object
implements SetWithDistrib

Multiset that allows sampling, but not iteration or removals. Uses a sorted map (from elements to integers) so the sampling is reproducible. Null elements cannot be added.


Constructor Summary
SamplingMultiset()
          Creates a new, empty multiset.
 
Method Summary
 int getCount(java.lang.Object o)
          Returns the count for the given element.
 double getLogProb(java.lang.Object o)
          Returns the natural log of the probability of the given object under this distribution.
 double getProb(java.lang.Object o)
          Returns the probability of the given object under this distribution.
 void incrementCount(java.lang.Object o)
          Increments the count for the given element.
 java.lang.Object sample()
          Returns an object sampled uniformly from this multiset.
 java.lang.String toString()
           
 int totalCount()
          Returns the total count of all elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SamplingMultiset

public SamplingMultiset()
Creates a new, empty multiset.

Method Detail

incrementCount

public void incrementCount(java.lang.Object o)
Increments the count for the given element.


getCount

public int getCount(java.lang.Object o)
Returns the count for the given element.


totalCount

public int totalCount()
Returns the total count of all elements.


getProb

public double getProb(java.lang.Object o)
Description copied from interface: SetWithDistrib
Returns the probability of the given object under this distribution. Returns zero if the object is not in this set.

Specified by:
getProb in interface SetWithDistrib

getLogProb

public double getLogProb(java.lang.Object o)
Description copied from interface: SetWithDistrib
Returns the natural log of the probability of the given object under this distribution. Returns Double.NEGATIVE_INFINITY if the object is not in this set.

Specified by:
getLogProb in interface SetWithDistrib

sample

public java.lang.Object sample()
Returns an object sampled uniformly from this multiset. If the multiset is empty, returns null.

Specified by:
sample in interface SetWithDistrib

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object