Package jsl.utilities.distributions
Class Constant
- java.lang.Object
-
- jsl.utilities.distributions.Distribution
-
- jsl.utilities.distributions.Constant
-
- All Implemented Interfaces:
ControllableIfc
,CDFIfc
,DiscreteDistributionIfc
,DistributionFunctionIfc
,DistributionIfc
,InverseCDFIfc
,MeanIfc
,PMFIfc
,VarianceIfc
,GetNameIfc
,IdentityIfc
,NewInstanceIfc
,ParametersIfc
,GetRVariableIfc
- Direct Known Subclasses:
VConstant
public class Constant extends Distribution implements DiscreteDistributionIfc, GetRVariableIfc
Constructs a degenerate distribution with all probability at the provided point. Once made the value of the constant cannot be changed.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.utilities.distributions.Distribution
Distribution.RandomControls
-
-
Field Summary
Fields Modifier and Type Field Description protected double
myValue
static Constant
ONE
A constant to represent one for sharingstatic Constant
POSITIVE_INFINITY
A constant to represent positive infinity for sharingstatic Constant
TWO
A constant to represent two for sharingstatic Constant
ZERO
A constant to represent zero for sharing-
Fields inherited from class jsl.utilities.distributions.Distribution
myId, myName
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
cdf(double x)
Returns the F(x) = Pr{X <= x} where F represents the cumulative distribution functiondouble
getMean()
Returns the mean or expected value of a distributiondouble[]
getParameters()
Gets the parametersRVariableIfc
getRandomVariable(RNStreamIfc rng)
double
getVariance()
Returns the variance of the distribution if defineddouble
invCDF(double p)
Provides the inverse cumulative distribution function for the distribution While closed form solutions for the inverse cdf may not exist, numerical search methods can be used to solve F(X) = U.Constant
newInstance()
Returns a new instancedouble
pmf(double x)
Returns the f(x) where f represents the probability mass function for the distribution.void
setParameters(double[] parameters)
Sets the parameters-
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
-
-
-
-
Field Detail
-
ZERO
public static final Constant ZERO
A constant to represent zero for sharing
-
ONE
public static final Constant ONE
A constant to represent one for sharing
-
TWO
public static final Constant TWO
A constant to represent two for sharing
-
POSITIVE_INFINITY
public static final Constant POSITIVE_INFINITY
A constant to represent positive infinity for sharing
-
myValue
protected double myValue
-
-
Constructor Detail
-
Constant
public Constant(double value)
Construct a constant using the supplied value- Parameters:
value
- the value for the constant
-
Constant
public Constant(double[] parameters)
- Parameters:
parameters
- the parameter[0] is the value
-
Constant
public Constant(double value, java.lang.String name)
Construct a constant using the supplied value- Parameters:
value
- the value for the constantname
- a string name/label
-
-
Method Detail
-
newInstance
public Constant newInstance()
Description copied from interface:NewInstanceIfc
Returns a new instance- Specified by:
newInstance
in interfaceNewInstanceIfc
- Specified by:
newInstance
in classDistribution
- Returns:
- the new instance
-
setParameters
public void setParameters(double[] parameters)
Description copied from interface:ParametersIfc
Sets the parameters- Specified by:
setParameters
in interfaceParametersIfc
- Parameters:
parameters
- an array of doubles representing the parameters
-
getParameters
public final double[] getParameters()
Description copied from interface:ParametersIfc
Gets the parameters- Specified by:
getParameters
in interfaceParametersIfc
- Returns:
- Returns an array of the parameters
-
pmf
public final double pmf(double x)
Description copied from interface:PMFIfc
Returns the f(x) where f represents the probability mass function for the distribution.
-
cdf
public final double cdf(double x)
Description copied from interface:CDFIfc
Returns the F(x) = Pr{X <= x} where F represents the cumulative distribution function
-
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
-
invCDF
public final double invCDF(double p)
Description copied from interface:InverseCDFIfc
Provides the inverse cumulative distribution function for the distribution While closed form solutions for the inverse cdf may not exist, numerical search methods can be used to solve F(X) = U.- Specified by:
invCDF
in interfaceInverseCDFIfc
- Parameters:
p
- The probability to be evaluated for the inverse, p must be [0,1] or an IllegalArgumentException is thrown- Returns:
- The inverse cdf evaluated at the supplied probability
-
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
-
-