Class DiscreteDistribution
java.lang.Object
random.AbstractDistribution
random.discrete.DiscreteDistribution
- All Implemented Interfaces:
StorableDistribution
- Direct Known Subclasses:
Bernoulli, Binomial, FixProbability, Poisson, ShiftedGeometric, Uniform, Zipf
public abstract class DiscreteDistribution
extends AbstractDistribution
implements StorableDistribution
Base class of the discrete probability distributions of the JMT random package.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanFields inherited from class AbstractDistribution
engine -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static intbinarySearch(int lower, int upper, double probability, Hashtable<Integer, Double> CDF_List) abstract doublecdf(int x) abstract doubleobtain the cumulative distribution from the distributioncreatedCDFList(int lower, int upper) Calculate the cumulative distribution value for each discrete random variable.createdCDFList(int lower, int upper, Parameter p) abstract intgetlower()abstract intgetUpper()protected intinverseTransformSampling(int lower, int upper) Inverse transform sampling Take an uniform distribution - u (0, 1) as the input probability.abstract intnextRand()These functions are used to direct initialize the Discrete Distribution.abstract intGenerate random variables that follow an probability distributionvoidoutdated()Set all cache flag false, call it when parameters changed.abstract doublepmf(int x) abstract doubleobtain the probability distribution from the distributionabstract doubleabstract doubleCalculate the Mean value from the parameter of the distributionabstract doubleabstract doubleCalculate the Variance from the parameter of the distributionabstract booleanSub-class must implement this method to update parameter.Methods inherited from class AbstractDistribution
setRandomEngine
-
Field Details
-
cached
protected boolean cached -
CDFList
-
CDFListCalculated
protected boolean CDFListCalculated
-
-
Constructor Details
-
DiscreteDistribution
public DiscreteDistribution()
-
-
Method Details
-
outdated
public void outdated()Set all cache flag false, call it when parameters changed. -
updatePar
Sub-class must implement this method to update parameter. -
getUpper
public abstract int getUpper() -
getlower
public abstract int getlower() -
inverseTransformSampling
protected int inverseTransformSampling(int lower, int upper) Inverse transform sampling Take an uniform distribution - u (0, 1) as the input probability. Find the CDF section that hold the probability generated by uniform distribution - u (0, 1). the upper bound of target section is the random variable that follow the specific distribution.
In each implementation of discrete distribution, the cumulative probability is calculated through `cdf()` this function will create the CDF List for each unit, because the cumulative probability is monotone increasing, use binary search to find the target section. -
createdCDFList
-
createdCDFList
protected Hashtable<Integer,Double> createdCDFList(int lower, int upper, Parameter p) throws IncorrectDistributionParameterException -
binarySearch
-
nextRand
public abstract int nextRand()These functions are used to direct initialize the Discrete Distribution. once invoke parameter constructor with the distribution parameter, set cached = true. if not cache the parameter, only method with `Parameter` are available. -
pmf
public abstract double pmf(int x) -
cdf
public abstract double cdf(int x) -
theorMean
public abstract double theorMean() -
theorVariance
public abstract double theorVariance() -
nextRand
Generate random variables that follow an probability distribution- Parameters:
p- parameter of the distribution.- Returns:
- int - random variables that follow an probability distribution
- Throws:
IncorrectDistributionParameterException
-
pmf
obtain the probability distribution from the distribution- Parameters:
x- int - random variable indicating where to evaluate the pmf.p- parameter of the distribution.- Returns:
- double - the probability weight evaluated at x.
- Throws:
IncorrectDistributionParameterException
-
cdf
obtain the cumulative distribution from the distribution- Parameters:
x- int - random variable indicating where to evaluate the cdf.p- parameter of the distribution.- Returns:
- double - the probability weight cumulated at x.
- Throws:
IncorrectDistributionParameterException
-
theorMean
Calculate the Mean value from the parameter of the distribution- Parameters:
p- parameter of the distribution.- Returns:
- double - theoretic mean value of the distribution.
- Throws:
IncorrectDistributionParameterException
-
theorVariance
Calculate the Variance from the parameter of the distribution- Parameters:
p- parameter of the distribution.- Returns:
- double - theoretic variance value of the distribution.
- Throws:
IncorrectDistributionParameterException
-