|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object common.Histogram
public class Histogram
A mapping from objects to weights, which are real numbers. A
Histogram maintains an internal map from objects to Doubles,
and also keeps track of the sum of the weights. If the
sorted
flag is specified at construction, then the
Histogram uses a sorted map so that sampling results are reproducible.
A histogram conceptually stores a weight for every object, but most
objects have zero weight. Only objects with non-zero weight are
explicitly represented. The iterator
method only allows you
to iterate over objects with non-zero weight; if you want to iterate
over other objects, you need to enumerate those objects in some other
way, and call getWeight
for each one.
Note: This class does not allow null elements to be added.
Nested Class Summary | |
---|---|
static class |
Histogram.Entry
Nested class for the entries in a histogram. |
Constructor Summary | |
---|---|
Histogram()
Creates an empty histogram. |
|
Histogram(boolean sorted)
Creates an empty histogram. |
Method Summary | |
---|---|
void |
clear()
Resets the weights of all objects to zero. |
java.util.Set |
elementSet()
Returns an unmodifiable view of the set of objects that have non-zero weight in this histogram. |
java.util.Set |
entrySet()
Returns an unmodifiable view of the set of Histogram.Entry objects corresponding to the non-zero weight objects in this histogram. |
double |
getLogProb(java.lang.Object o)
Returns the log probability of the given object being sampled, according to its weight. |
double |
getProb(java.lang.Object o)
Returns the probability of the given object being sampled, according to its weight. |
double |
getTotalWeight()
Returns the sum of the weights of all objects in this histogram. |
double |
getWeight(java.lang.Object obj)
Returns the weight of the given object in this histogram. |
void |
increaseWeight(java.lang.Object obj,
double delta)
Increases the weight for the given object by the given amount. |
void |
print(java.io.PrintStream s)
Prints this histogram to the given stream. |
java.lang.Object |
sample()
Returns an object sampled according to this distribution. |
int |
size()
Returns the number of objects that have non-zero weight in this histogram. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Histogram()
public Histogram(boolean sorted)
sorted
- if true, use a sorted map from elements to weightsMethod Detail |
---|
public int size()
public double getWeight(java.lang.Object obj)
public double getTotalWeight()
public double getProb(java.lang.Object o)
getProb
in interface SetWithDistrib
public double getLogProb(java.lang.Object o)
getLogProb
in interface SetWithDistrib
public void increaseWeight(java.lang.Object obj, double delta)
public void clear()
public java.util.Set elementSet()
public java.util.Set entrySet()
public java.lang.Object sample()
SetWithDistrib
sample
in interface SetWithDistrib
public void print(java.io.PrintStream s)
sorted
flag set to true, then the entries are sorted by key.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |