Package jsl.utilities.distributions
Class Bernoulli
- java.lang.Object
-
- jsl.utilities.distributions.Distribution
-
- jsl.utilities.distributions.Bernoulli
-
- All Implemented Interfaces:
ControllableIfc
,CDFIfc
,DiscreteDistributionIfc
,DistributionFunctionIfc
,DistributionIfc
,InverseCDFIfc
,MeanIfc
,PMFIfc
,VarianceIfc
,GetNameIfc
,IdentityIfc
,NewInstanceIfc
,ParametersIfc
,GetRVariableIfc
public class Bernoulli extends Distribution implements DiscreteDistributionIfc, GetRVariableIfc
An Bernouli provides an implementation of the Bernouli distribution with success probability (p) P(X=1) = p P(X=0) = 1-p
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.utilities.distributions.Distribution
Distribution.RandomControls
-
-
Field Summary
-
Fields inherited from class jsl.utilities.distributions.Distribution
myId, myName
-
-
Constructor Summary
Constructors Constructor Description Bernoulli()
Constructs a probability distribution, the default is Bernouli(0.5)Bernoulli(double prob)
Constructs a probability distribution with the default random number generator,Bernoulli(double[] parameters)
Constructs a probability distribution with the default random number generator,Bernoulli(double prob, java.lang.String name)
Constructs a probability distribution with the default random number generator,
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
cdf(double xx)
Returns the P(X<=x)double
getMean()
Returns the mean of the distribution if defineddouble[]
getParameters()
Gets the parameters for the distributiondouble
getProbabilityOfSuccess()
Gets the success probabilityRVariableIfc
getRandomVariable(RNStreamIfc rng)
double
getVariance()
Returns the variance of the random variate if defineddouble
invCDF(double prob)
Returns the value of x such that p = Pr{X <= x} where F represents the cumulative distribution functionBernoulli
newInstance()
Returns a new instance of the random source with the same parameters but an independent generatordouble
pmf(double x)
Returns the f(x) where f represents the probability mass function for the distribution.double
pmf(int x)
Returns the f(x) where f represents the probability mass function for the distribution.void
setParameters(double[] parameters)
Sets the parameters for the distributionvoid
setProbabilityOfSuccess(double prob)
Sets the success probability-
Methods inherited from class jsl.utilities.distributions.Distribution
getControls, getId, getName, getStandardDeviation, inverseContinuousCDFViaBisection, inverseContinuousCDFViaBisection, inverseDiscreteCDFViaSearchUp, setControls, setId, setName, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.distributions.CDFIfc
cdf, complementaryCDF
-
Methods inherited from interface jsl.utilities.random.rvariable.GetRVariableIfc
getRandomVariable, getRandomVariable
-
-
-
-
Constructor Detail
-
Bernoulli
public Bernoulli()
Constructs a probability distribution, the default is Bernouli(0.5)
-
Bernoulli
public Bernoulli(double[] parameters)
Constructs a probability distribution with the default random number generator,- Parameters:
parameters
- should be an array with parameter[0]=p
-
Bernoulli
public Bernoulli(double prob)
Constructs a probability distribution with the default random number generator,- Parameters:
prob
- is the success probability
-
Bernoulli
public Bernoulli(double prob, java.lang.String name)
Constructs a probability distribution with the default random number generator,- Parameters:
prob
- is the success probabilityname
- a string label
-
-
Method Detail
-
newInstance
public final Bernoulli newInstance()
Returns a new instance of the random source with the same parameters but an independent generator- Specified by:
newInstance
in interfaceNewInstanceIfc
- Specified by:
newInstance
in classDistribution
- Returns:
-
setProbabilityOfSuccess
public final void setProbabilityOfSuccess(double prob)
Sets the success probability- Parameters:
prob
- The success probability
-
getProbabilityOfSuccess
public final double getProbabilityOfSuccess()
Gets the success probability- Returns:
- The success probability
-
cdf
public final double cdf(double xx)
Returns the P(X<=x)
-
invCDF
public final double invCDF(double prob)
Returns the value of x such that p = Pr{X <= x} where F represents the cumulative distribution function- Specified by:
invCDF
in interfaceInverseCDFIfc
- Parameters:
prob
- a double representing the probability- Returns:
- a double representing the bernoulli variate
-
getMean
public final double getMean()
Returns the mean of the distribution if defined
-
pmf
public final double pmf(double x)
Returns the f(x) where f represents the probability mass function for the distribution. If JSLMath.equal(x,1.0) the probability of success is returned If JSLMath.equal(x,0.0) the probability of failure is returned otherwise 0.0 is returned.
-
pmf
public final double pmf(int x)
Returns the f(x) where f represents the probability mass function for the distribution.- Parameters:
x
- an int representing the value to be evaluated- Returns:
- f(x)
-
getVariance
public final double getVariance()
Returns the variance of the random variate if defined- Specified by:
getVariance
in interfaceVarianceIfc
- Returns:
- double the variance of the random variable
-
setParameters
public final void setParameters(double[] parameters)
Sets the parameters for the distribution- Specified by:
setParameters
in interfaceParametersIfc
- Parameters:
parameters
- an array of doubles representing the parameters for the distribution
-
getParameters
public final double[] getParameters()
Gets the parameters for the distribution- Specified by:
getParameters
in interfaceParametersIfc
- Returns:
- Returns an array of the parameters for the distribution
-
getRandomVariable
public final RVariableIfc getRandomVariable(RNStreamIfc rng)
- Specified by:
getRandomVariable
in interfaceGetRVariableIfc
- Overrides:
getRandomVariable
in classDistribution
- Parameters:
rng
- the stream to use- Returns:
- a random variable
-
-