Package jsl.utilities.distributions
Class DEmpiricalCDF
- java.lang.Object
-
- jsl.utilities.distributions.Distribution
-
- jsl.utilities.distributions.DEmpiricalCDF
-
- All Implemented Interfaces:
ControllableIfc
,CDFIfc
,DiscreteDistributionIfc
,DistributionFunctionIfc
,DistributionIfc
,InverseCDFIfc
,MeanIfc
,PMFIfc
,VarianceIfc
,GetNameIfc
,IdentityIfc
,NewInstanceIfc
,ParametersIfc
,GetRVariableIfc
public class DEmpiricalCDF extends Distribution implements DiscreteDistributionIfc, GetRVariableIfc
Provides a representation for a discrete distribution with arbitrary values and assigned probabilities to each value. Allows the specification of the distribution via a pair of arrays containing the values = {v1, v2, ... , vn} and the cumulative probabilities cdf = {c1, c2, ... , 1.0} where if p1 is the probability associated with v1, p2 with v2, etc then c1 = p1, c2 = p1 + p2, c3 = p1 + p2 + p3, etc, with cn = 1.0 (the sum of all the probabilities). If cn is not 1.0, then an exception is thrown.
-
-
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 DEmpiricalCDF(double[] values, double[] cdf)
DEmpiricalCDF(double[] values, double[] cdf, java.lang.String name)
(v[0], cdf[0], ...) represent the value and the cumulative probability of that value.
-
Method Summary
All Methods Static 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 parameters for the distributionRVariableIfc
getRandomVariable(RNStreamIfc rng)
double
getVariance()
Returns the variance of the distribution if defineddouble
invCDF(double p)
Provides the inverse cumulative distribution function for the distributionstatic void
main(java.lang.String[] args)
static double[]
makePairs(double[] cdf)
Assigns the probability associated with each cdf value to the integers starting at 0.static double[]
makePairs(double[] values, double[] cdf)
Makes a pair array that can be used for the parameters of the DEmpiricalCDF distributionstatic double[]
makePairs(int start, double[] cdf)
Assigns the probability associated with each cdf value to the integers starting at start.DEmpiricalCDF
newInstance()
Returns a new instancedouble
pmf(double x)
The probability mass function for this discrete distribution.void
setParameters(double[] parameters)
Sets the parameters for the distribution.static double[][]
splitPairs(double[] pairs)
This method takes in an Array of probability points (value, cumulative probability), Eg.java.lang.String
toString()
Returns the pmf as a string.-
Methods inherited from class jsl.utilities.distributions.Distribution
getControls, getId, getName, getStandardDeviation, inverseContinuousCDFViaBisection, inverseContinuousCDFViaBisection, inverseDiscreteCDFViaSearchUp, setControls, setId, setName
-
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
-
DEmpiricalCDF
public DEmpiricalCDF(double[] values, double[] cdf)
- Parameters:
values
- an array of values that will be drawn fromcdf
- a cdf corresponding to the values
-
DEmpiricalCDF
public DEmpiricalCDF(double[] values, double[] cdf, java.lang.String name)
(v[0], cdf[0], ...) represent the value and the cumulative probability of that value.- Parameters:
values
- an array of values that will be drawn fromcdf
- a cdf corresponding to the valuesname
- an optional name/label
-
-
Method Detail
-
makePairs
public static double[] makePairs(double[] cdf)
Assigns the probability associated with each cdf value to the integers starting at 0.- Parameters:
cdf
- the probability array. must have valid probability elements and last element equal to 1. Every element must be greater than or equal to the previous element. That is, monotonically increasing.- Returns:
- the pairs
-
makePairs
public static double[] makePairs(int start, double[] cdf)
Assigns the probability associated with each cdf value to the integers starting at start.- Parameters:
start
- place to start assignmentcdf
- the probability array. must have valid probability elements and last element equal to 1. Every element must be greater than or equal to the previous element. That is, monotonically increasing.- Returns:
- the pairs
-
splitPairs
public static double[][] splitPairs(double[] pairs)
This method takes in an Array of probability points (value, cumulative probability), Eg. X[] = {v1, cp1, v2, cp2, ...}, as the input parameter and makes a 2D array of the value/prob pairs- Parameters:
pairs
- An array holding the value, cumulative probability pairs.
-
makePairs
public static double[] makePairs(double[] values, double[] cdf)
Makes a pair array that can be used for the parameters of the DEmpiricalCDF distribution- Parameters:
values
- an array of values that will be drawn fromcdf
- a cdf corresponding to the values- Returns:
- a properly configured array of pairs for the DEmpiricalCDF distribution
-
newInstance
public final DEmpiricalCDF newInstance()
Description copied from interface:NewInstanceIfc
Returns a new instance- Specified by:
newInstance
in interfaceNewInstanceIfc
- Specified by:
newInstance
in classDistribution
- Returns:
- the new instance
-
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
-
pmf
public final double pmf(double x)
The probability mass function for this discrete distribution. Returns the same as pdf.
-
toString
public java.lang.String toString()
Returns the pmf as a string.- Overrides:
toString
in classDistribution
- Returns:
- A String of probability, value pairs.
-
invCDF
public double invCDF(double p)
Provides the inverse cumulative distribution function for the distribution- 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 p
-
setParameters
public final void setParameters(double[] parameters)
Sets the parameters for the distribution. Array of probability points (value, cumulative probability), Eg. X[] = [v1, cp1, v2, cp2, 7,0.5], as the input parameters.- Specified by:
setParameters
in interfaceParametersIfc
- Parameters:
parameters
- an array of doubles representing the parameters for the distribution
-
getParameters
public 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
-
main
public static void main(java.lang.String[] args)
-
-