Package jsl.utilities.distributions
Class Geometric
- java.lang.Object
-
- jsl.utilities.distributions.Distribution
-
- jsl.utilities.distributions.Geometric
-
- All Implemented Interfaces:
ControllableIfc
,CDFIfc
,DiscreteDistributionIfc
,DistributionFunctionIfc
,DistributionIfc
,FirstOrderLossFunctionIfc
,InverseCDFIfc
,LossFunctionDistributionIfc
,MeanIfc
,PMFIfc
,SecondOrderLossFunctionIfc
,VarianceIfc
,GetNameIfc
,IdentityIfc
,NewInstanceIfc
,ParametersIfc
,GetRVariableIfc
public class Geometric extends Distribution implements DiscreteDistributionIfc, LossFunctionDistributionIfc, GetRVariableIfc
The geometric distribution is the probability distribution of the number Y = X − 1 of failures before the first success, supported on the set { 0, 1, 2, 3, ... }, where X is the number of Bernoulli trials needed to get one success.
-
-
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 Geometric()
Constructs a Geometric with success probability = 0.5Geometric(double prob)
Constructs a Geometric using the supplied success probabilityGeometric(double[] parameters)
Constructs a Geometric using the supplied parameters array parameters[0] is probability of successGeometric(double prob, java.lang.String name)
Constructs a Geometric using the supplied success probability and lower range
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
canMatchMoments(double... moments)
double
cdf(double x)
computes the cdf of the distribution F(X<=x)static Geometric
createFromMoments(double... moments)
double
firstOrderLossFunction(double x)
Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]double
getMean()
Returns the mean or expected value of a distributiondouble[]
getParameters()
Gets the parameters as an array parameters[0] is probability of successstatic double[]
getParametersFromMoments(double... moments)
double
getProbabilityOfSuccess()
Gets the probability of successRVariableIfc
getRandomVariable(RNStreamIfc rng)
double
getVariance()
Returns the variance of the distribution if defineddouble
invCDF(double prob)
Gets the inverse cdf for the distributionGeometric
newInstance()
Returns a new instancedouble
pmf(double x)
If x is not and integer value, then the probability must be zero otherwise pmf(int x) is used to determine the probabilitydouble
pmf(int x)
computes the pmf of the distribution f(x) = p(1-p)^(x) for x>=0, 0 otherwisedouble
secondOrderLossFunction(double x)
Computes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]void
setParameters(double[] parameters)
Sets the parameters using the supplied array parameters[0] is probability of success parameters[1] is lower rangevoid
setProbabilityOfSuccess(double prob)
Sets the probability of success-
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
-
Methods inherited from interface jsl.utilities.distributions.VarianceIfc
getStandardDeviation
-
-
-
-
Constructor Detail
-
Geometric
public Geometric()
Constructs a Geometric with success probability = 0.5
-
Geometric
public Geometric(double[] parameters)
Constructs a Geometric using the supplied parameters array parameters[0] is probability of success- Parameters:
parameters
- the parameter array
-
Geometric
public Geometric(double prob)
Constructs a Geometric using the supplied success probability- Parameters:
prob
- , the probability of success
-
Geometric
public Geometric(double prob, java.lang.String name)
Constructs a Geometric using the supplied success probability and lower range- Parameters:
prob
- the probability of successname
- an optional label/name
-
-
Method Detail
-
newInstance
public final Geometric newInstance()
Description copied from interface:NewInstanceIfc
Returns a new instance- Specified by:
newInstance
in interfaceNewInstanceIfc
- Specified by:
newInstance
in classDistribution
- Returns:
- the new instance
-
setProbabilityOfSuccess
public final void setProbabilityOfSuccess(double prob)
Sets the probability of success- Parameters:
prob
- the probability of success
-
getProbabilityOfSuccess
public final double getProbabilityOfSuccess()
Gets the probability of success- Returns:
- the probability of success
-
getMean
public final double getMean()
Description copied from interface:MeanIfc
Returns the mean or expected value of a distribution
-
getVariance
public final double getVariance()
Description copied from interface:VarianceIfc
Returns the variance of the distribution 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 using the supplied array parameters[0] is probability of success parameters[1] is lower range- Specified by:
setParameters
in interfaceParametersIfc
- Parameters:
parameters
- the parameter array
-
getParameters
public final double[] getParameters()
Gets the parameters as an array parameters[0] is probability of success- Specified by:
getParameters
in interfaceParametersIfc
- Returns:
- Returns an array of the parameters
-
pmf
public final double pmf(int x)
computes the pmf of the distribution f(x) = p(1-p)^(x) for x>=0, 0 otherwise- Parameters:
x
- the value to evaluate- Returns:
- the probability
-
pmf
public final double pmf(double x)
If x is not and integer value, then the probability must be zero otherwise pmf(int x) is used to determine the probability
-
cdf
public final double cdf(double x)
computes the cdf of the distribution F(X<=x)
-
invCDF
public final double invCDF(double prob)
Gets the inverse cdf for the distribution- Specified by:
invCDF
in interfaceInverseCDFIfc
- Parameters:
prob
- Must be in range [0,1)- Returns:
- The inverse cdf evaluated at the supplied probability
-
canMatchMoments
public static boolean canMatchMoments(double... moments)
-
getParametersFromMoments
public static double[] getParametersFromMoments(double... moments)
-
createFromMoments
public static Geometric createFromMoments(double... moments)
-
firstOrderLossFunction
public double firstOrderLossFunction(double x)
Description copied from interface:FirstOrderLossFunctionIfc
Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]- Specified by:
firstOrderLossFunction
in interfaceFirstOrderLossFunctionIfc
- Parameters:
x
- The value to be evaluated- Returns:
- The loss function value, E[max(X-x,0)]
-
secondOrderLossFunction
public double secondOrderLossFunction(double x)
Description copied from interface:SecondOrderLossFunctionIfc
Computes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]- Specified by:
secondOrderLossFunction
in interfaceSecondOrderLossFunctionIfc
- Parameters:
x
- The value to be evaluated- Returns:
- The loss function value, (1/2)E[max(X-x,0)*max(X-x-1,0)]
-
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
-
-