common
Class LogHistogram

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

public class LogHistogram
extends java.lang.Object
implements SetWithDistrib

A histogram that stores the logs of the weights of its elements, rather than the weights themselves.


Constructor Summary
LogHistogram()
          Creates a new LogHistogram with no elements.
LogHistogram(boolean sorted)
          Creates a new LogHistogram with no elements.
 
Method Summary
 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 increaseWeight(java.lang.Object o, double logIncrement)
          Increases the weight of the given object by an amount whose logarithm is the given value.
 java.lang.Object sample()
          Returns an object sampled according to this distribution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogHistogram

public LogHistogram()
Creates a new LogHistogram with no elements.


LogHistogram

public LogHistogram(boolean sorted)
Creates a new LogHistogram with no elements.

Parameters:
sorted - if true, use a sorted map from elements to log weights
Method Detail

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()
Description copied from interface: SetWithDistrib
Returns an object sampled according to this distribution. Returns null if this set is empty.

Specified by:
sample in interface SetWithDistrib

increaseWeight

public void increaseWeight(java.lang.Object o,
                           double logIncrement)
Increases the weight of the given object by an amount whose logarithm is the given value.