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 booleancanMatchMoments(double... moments)doublecdf(double x)computes the cdf of the distribution F(X<=x)static GeometriccreateFromMoments(double... moments)doublefirstOrderLossFunction(double x)Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]doublegetMean()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)doublegetProbabilityOfSuccess()Gets the probability of successRVariableIfcgetRandomVariable(RNStreamIfc rng)doublegetVariance()Returns the variance of the distribution if defineddoubleinvCDF(double prob)Gets the inverse cdf for the distributionGeometricnewInstance()Returns a new instancedoublepmf(double x)If x is not and integer value, then the probability must be zero otherwise pmf(int x) is used to determine the probabilitydoublepmf(int x)computes the pmf of the distribution f(x) = p(1-p)^(x) for x>=0, 0 otherwisedoublesecondOrderLossFunction(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)]voidsetParameters(double[] parameters)Sets the parameters using the supplied array parameters[0] is probability of success parameters[1] is lower rangevoidsetProbabilityOfSuccess(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:NewInstanceIfcReturns a new instance- Specified by:
newInstancein interfaceNewInstanceIfc- Specified by:
newInstancein 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:MeanIfcReturns the mean or expected value of a distribution
-
getVariance
public final double getVariance()
Description copied from interface:VarianceIfcReturns the variance of the distribution if defined- Specified by:
getVariancein 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:
setParametersin 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:
getParametersin 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:
invCDFin 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:FirstOrderLossFunctionIfcComputes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]- Specified by:
firstOrderLossFunctionin 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:SecondOrderLossFunctionIfcComputes 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:
secondOrderLossFunctionin 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:
getRandomVariablein interfaceGetRVariableIfc- Overrides:
getRandomVariablein classDistribution- Parameters:
rng- the stream to use- Returns:
- a random variable
-
-