All Packages Class Hierarchy This Package Previous Next Index
Class sdsu.algorithms.data.Bernoulli
java.lang.Object
|
+----sdsu.algorithms.data.ProbabilityDistribution
|
+----sdsu.algorithms.data.DiscreteProbability
|
+----sdsu.algorithms.data.Bernoulli
- 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)
-
Bernoulli(double)
- Returns a Bernoulli with the propability of success equal to
successProbability.
-
density(double)
- Returns the probability of an item in the sample
space will occur.
-
mean()
- Returns the mean of the Bernoulli distribution
-
nextElement()
- Returns 1 or 0.
-
variance()
- Returns the variance of the probability distribution
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.
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
All Packages Class Hierarchy This Package Previous Next Index