common
Class BinarySequenceDistrib

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

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

A distribution over sequences of independent, identically distributed binary variables. It has one parameter: the probability that any given element in the sequence is true.

See Also:
Serialized Form

Constructor Summary
BinarySequenceDistrib()
          Creates a BinarySequenceDistrib object with the probability of any element being true set to 0.5.
BinarySequenceDistrib(double p)
          Creates a BinarySequenceDistrib object with the probability of any element being true set to p.
 
Method Summary
 void collectStats(java.util.BitSet s, int n)
          Records the occurrence of an array of length n, where the set of true elements is specified by the given BitSet.
 void collectStats(boolean[] x)
          Records an occurrence of the array x, for use in updating parameters.
 double getLogProb(java.util.BitSet s, int n)
          Returns the log probability of an array of length n, where the set of true elements is specified by the given BitSet.
 double getLogProb(boolean[] x)
          Returns the log of the probability of the given array of values.
 double getProb(java.util.BitSet s, int n)
          Returns the probability of an array of length n, where the set of true elements is specified by the given BitSet.
 double getProb(boolean[] x)
          Returns the probability of the given array of values.
 double updateParams()
          Sets the parameter probTrue to the value that maximizes the likelihood of the arrays 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

BinarySequenceDistrib

public BinarySequenceDistrib()
Creates a BinarySequenceDistrib object with the probability of any element being true set to 0.5.


BinarySequenceDistrib

public BinarySequenceDistrib(double p)
Creates a BinarySequenceDistrib object with the probability of any element being 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 given array of values.


getProb

public double getProb(java.util.BitSet s,
                      int n)
Returns the probability of an array of length n, where the set of true elements is specified by the given BitSet.


getLogProb

public double getLogProb(boolean[] x)
Returns the log of the probability of the given array of values.


getLogProb

public double getLogProb(java.util.BitSet s,
                         int n)
Returns the log probability of an array of length n, where the set of true elements is specified by the given BitSet.


collectStats

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


collectStats

public void collectStats(java.util.BitSet s,
                         int n)
Records the occurrence of an array of length n, where the set of true elements is specified by the given BitSet.


updateParams

public double updateParams()
Sets the parameter probTrue to the value that maximizes the likelihood of the arrays 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.