sdsu.algorithms.data
Class Bernoulli

java.lang.Object
  |
  +--sdsu.algorithms.data.ProbabilityDistribution
        |
        +--sdsu.algorithms.data.DiscreteProbability
              |
              +--sdsu.algorithms.data.Bernoulli
Direct Known Subclasses:
Geometric

public class Bernoulli
extends DiscreteProbability

A Bernoulli distribution is defined on a sample space of two events. For example: tossing a coin, did I get heads?; Throwing a die, did I get die side 5?. This class labels the two items in the sample space as 0 (failure) and 1 (success). Giving the probability of the success event (1) also determince the probability of failure. This class is adapted from Smalltalk-80: The language and Its Implementation, Goldberg & Robson, Addison-Wesley, 1983, chapter 21, pages 417-438.

Version:
1.0 10 June 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)

Constructor Summary
Bernoulli(double successProbability)
          Returns a Bernoulli with the propability of success equal to successProbability.
 
Method Summary
 double density(double sampleSpaceItem)
          Returns the probability of an item in the sample space will occur.
 double mean()
          Returns the mean of the Bernoulli distribution
 double nextElement()
          Returns 1 or 0.
 double variance()
          Returns the variance of the probability distribution
 
Methods inherited from class sdsu.algorithms.data.DiscreteProbability
distribution
 
Methods inherited from class sdsu.algorithms.data.ProbabilityDistribution
density
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bernoulli

public Bernoulli(double successProbability)
          throws OutOfBoundsException
Returns a Bernoulli with the propability of success equal to successProbability.
Throws:
OutOfBoundsException - thrown if successProbability is not between 0 and 1.
Method Detail

density

public double density(double sampleSpaceItem)
               throws OutOfBoundsException
Returns the probability of an item in the sample space will occur. sampleSpaceItem must be either 0 or 1.
Parameters:
sampleSpaceItem - item in the sample space for which the probability of occuring is computed.
Throws:
OutOfBoundsException - thrown if sampleSpaceItem is not either 0 or 1.
Overrides:
density in class ProbabilityDistribution

mean

public double mean()
Returns the mean of the Bernoulli distribution
Overrides:
mean in class ProbabilityDistribution

variance

public double variance()
Returns the variance of the probability distribution
Overrides:
variance in class ProbabilityDistribution

nextElement

public double nextElement()
Returns 1 or 0. 1 is returned with the probability of success, set in the constructor.
Overrides:
nextElement in class ProbabilityDistribution