blog.distrib
Class Binomial

java.lang.Object
  extended by blog.AbstractCondProbDistrib
      extended by blog.distrib.Binomial
All Implemented Interfaces:
CondProbDistrib

public class Binomial
extends AbstractCondProbDistrib

A Binomial distribution with parameters n (number of trials) and p (probability of success for a given trial). The probability of k successes P(k)= C(n,k) * p^k * (1-p)^(n-k). A Binomial distribution can be created in the following ways:


Constructor Summary
Binomial(int n, double p)
          Creates a new Binomial distribution with parameters n and p.
Binomial(java.util.List params)
          Creates a new Binomial distribution.
 
Method Summary
 double getLogProb(java.util.List args, java.lang.Object value)
          Returns the log of the probability of integer k under the distribution.
 double getProb(java.util.List args, java.lang.Object value)
          Returns the probability of integer k under this distribution.
 java.lang.Object sampleVal(java.util.List args, Type childType)
          Returns an integer sampled according to this distribution.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Binomial

public Binomial(int n,
                double p)
Creates a new Binomial distribution with parameters n and p.


Binomial

public Binomial(java.util.List params)
Creates a new Binomial distribution. If two parameters are given, they are interpreted as n and p. If one parameter is given, it is interpreted as p and this distribution expects n as an argument. If no parameters are given, this distribution expects both n and p as arguments.

Method Detail

getProb

public double getProb(java.util.List args,
                      java.lang.Object value)
Returns the probability of integer k under this distribution.


getLogProb

public double getLogProb(java.util.List args,
                         java.lang.Object value)
Returns the log of the probability of integer k under the distribution.

Specified by:
getLogProb in interface CondProbDistrib
Overrides:
getLogProb in class AbstractCondProbDistrib

sampleVal

public java.lang.Object sampleVal(java.util.List args,
                                  Type childType)
Returns an integer sampled according to this distribution. Takes time proprotional to np + 1. (Reference: Non-Uniform Random Variate Generation, Devroye http://cgm.cs.mcgill.ca/~luc/rnbookindex.html) Second time-waiting algorithm.


toString

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