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 Details

    • cached

      protected boolean cached
    • CDFList

      protected Hashtable<Integer,Double> 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

      public abstract boolean updatePar(Parameter p) throws IncorrectDistributionParameterException
      Sub-class must implement this method to update parameter.
      Throws:
      IncorrectDistributionParameterException
    • 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

      protected Hashtable<Integer,Double> createdCDFList(int lower, int upper)
      Calculate the cumulative distribution value for each discrete random variable. It depends on the `cdf()` implementation from its subclass. result include lower and upper [lower, upper]
    • createdCDFList

      protected Hashtable<Integer,Double> createdCDFList(int lower, int upper, Parameter p) throws IncorrectDistributionParameterException
      Throws:
      IncorrectDistributionParameterException
    • binarySearch

      protected static int binarySearch(int lower, int upper, double probability, Hashtable<Integer,Double> CDF_List)
    • 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

      public abstract int nextRand(Parameter p) throws IncorrectDistributionParameterException
      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

      public abstract double pmf(int x, Parameter p) throws IncorrectDistributionParameterException
      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

      public abstract double cdf(int x, Parameter p) throws IncorrectDistributionParameterException
      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

      public abstract double theorMean(Parameter p) throws IncorrectDistributionParameterException
      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

      public abstract double theorVariance(Parameter p) throws IncorrectDistributionParameterException
      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