common
Class Bernoulli

java.lang.Object
  extended by common.Bernoulli
All Implemented Interfaces:
java.io.Serializable

public class Bernoulli
extends java.lang.Object
implements java.io.Serializable

A distribution over {true, false}. It has one parameter, the probability of the value true.

See Also:
Serialized Form

Constructor Summary
Bernoulli()
          Creates a Bernoulli object with the probability of true set to 0.5.
Bernoulli(double p)
          Creates a Bernoulli object with the probability of true set to p.
 
Method Summary
 void collectStats(boolean x)
          Records an occurrence of the value x, for use in updating parameters.
 double getLogProb(boolean x)
          Returns the log of the probability of the Boolean value x.
 double getProb(boolean x)
          Returns the probability of the Boolean value x.
 double updateParams()
          Sets the parameter probTrue to the value that maximizes the likelihood of the values passed to collectStats since the last call to updateParams.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bernoulli

public Bernoulli()
Creates a Bernoulli object with the probability of true set to 0.5.


Bernoulli

public Bernoulli(double p)
Creates a Bernoulli object with the probability of true set to p.

Throws:
java.lang.IllegalArgumentException - if p < 0 or p > 1.
Method Detail

getProb

public double getProb(boolean x)
Returns the probability of the Boolean value x.


getLogProb

public double getLogProb(boolean x)
Returns the log of the probability of the Boolean value x.


collectStats

public void collectStats(boolean x)
Records an occurrence of the value x, for use in updating parameters.


updateParams

public double updateParams()
Sets the parameter probTrue to the value that maximizes the likelihood of the values passed to collectStats since the last call to updateParams. Then clears the collected statistics, and returns the difference between the log likelihood of the data under the new parameters and the log likelihood under the old parameters.