Class AbstractEmpiricalDistribution

java.lang.Object
nl.tudelft.simulation.jstats.distributions.empirical.AbstractEmpiricalDistribution
All Implemented Interfaces:
Serializable, EmpiricalDistributionInterface
Direct Known Subclasses:
DiscreteEmpiricalDistribution, InterpolatedEmpiricalDistribution

public abstract class AbstractEmpiricalDistribution extends Object implements EmpiricalDistributionInterface
The AbstractEmpiricalDistribution implements the logic for a cumulative distribution function for an empirical distribution. In other words, it describes an ordered list of pairs (cumulative probability, value) from which values can be drawn using the inverse function method with a Uniform(0, 1) random distribution.

Copyright (c) 2021-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Author:
Alexander Verbraeck
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractEmpiricalDistribution(Number[] values, double[] cumulativeProbabilities)
    Construct the empirical distribution based on two arrays of the same length, one with sorted values, and one with corresponding sorted cumulative probabilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    getCeilingEntry(double cumulativeProbability)
    Return the cumulative probability and number above or at the given probability, or null when the cumulative probability is larger than the highest cumulative probability (1.0).
    Return the cumulative probability and number above or at the given value, or null when the value is larger than the highest value in the distribution.
    Returns the cumulative probabilities as a list.
    getFloorEntry(double cumulativeProbability)
    Return the cumulative probability and number below or at the given probability, or null when the cumulative probability is smaller than the lowest cumulative probability.
    Return the cumulative probability and number below or at the given value, or null when the value is smaller than the lowest value in the distribution.
    Return the highest value that this empirical distribution can return.
    Return the lowest value that this empirical distribution can return.
    getNextEntry(double cumulativeProbability)
    Return the cumulative probability and number that follows in the sequence with respect to the given probability, or null when the cumulative probability is larger than the highest cumulative probability.
    getPrevEntry(double cumulativeProbability)
    Return the cumulative probability and number that precedes in the sequence with respect to the given probability, or null when the cumulative probability is smaller than the lowest cumulative probability.
    Returns the values as a list.
    int
    int
    Returns the number of probability-value mappings in this structure.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AbstractEmpiricalDistribution

      public AbstractEmpiricalDistribution(Number[] values, double[] cumulativeProbabilities)
      Construct the empirical distribution based on two arrays of the same length, one with sorted values, and one with corresponding sorted cumulative probabilities. This constructor assumes that the arrays have been properly cloned to avoid changes to their content after the construction of the distribution. Tests for arrays not being equal to null should have been carried out when calling this constructor.
      Parameters:
      values - Number[] Number[]; the values belonging to each cumulative probability
      cumulativeProbabilities - double[]; the cumulative probabilities
      Throws:
      NullPointerException - when one of the values is null
      IllegalArgumentException - when cumulativeProbabilities array or values array are empty, or have unequal length, or when cumulativeProbabilities are not between 0 and 1, or when cumulativeProbabilities are not in ascending order, or when values are not in ascending order, or when the last cumulative probability is not 1.0
  • Method Details

    • size

      public int size()
      Returns the number of probability-value mappings in this structure.
      Specified by:
      size in interface EmpiricalDistributionInterface
      Returns:
      int; the number of probability-value mappings in this structure.
    • getCumulativeProbabilities

      public List<Double> getCumulativeProbabilities()
      Returns the cumulative probabilities as a list.
      Specified by:
      getCumulativeProbabilities in interface EmpiricalDistributionInterface
      Returns:
      the list of cumulative probabilities
    • getValues

      public List<Number> getValues()
      Returns the values as a list.
      Specified by:
      getValues in interface EmpiricalDistributionInterface
      Returns:
      the list of values
    • getFloorEntry

      public DistributionEntry getFloorEntry(double cumulativeProbability)
      Return the cumulative probability and number below or at the given probability, or null when the cumulative probability is smaller than the lowest cumulative probability.
      Specified by:
      getFloorEntry in interface EmpiricalDistributionInterface
      Parameters:
      cumulativeProbability - double; the cumulative probability to look up
      Returns:
      DistributionEntry; an entry object with the probability and corresponding value below or at the provided cumulative probability. Return null when the cumulative probability is smaller than the lowest cumulative probability
    • getCeilingEntry

      public DistributionEntry getCeilingEntry(double cumulativeProbability)
      Return the cumulative probability and number above or at the given probability, or null when the cumulative probability is larger than the highest cumulative probability (1.0).
      Specified by:
      getCeilingEntry in interface EmpiricalDistributionInterface
      Parameters:
      cumulativeProbability - double; the cumulative probability to look up
      Returns:
      DistributionEntry; an entry object with the probability and corresponding value above or at the provided cumulative probability. Return null when the cumulative probability is larger than the highest cumulative probability (1.0)
    • getPrevEntry

      public DistributionEntry getPrevEntry(double cumulativeProbability)
      Return the cumulative probability and number that precedes in the sequence with respect to the given probability, or null when the cumulative probability is smaller than the lowest cumulative probability. When cumulativeProbability is not a key, the floorEntry is returned instead.
      Specified by:
      getPrevEntry in interface EmpiricalDistributionInterface
      Parameters:
      cumulativeProbability - double; the cumulative probability to look up
      Returns:
      DistributionEntry; the first entry object with the probability and corresponding value below (but not at) the provided cumulative probability. Return null when the cumulative probability is smaller than the lowest cumulative probability
    • getNextEntry

      public DistributionEntry getNextEntry(double cumulativeProbability)
      Return the cumulative probability and number that follows in the sequence with respect to the given probability, or null when the cumulative probability is larger than the highest cumulative probability. When cumulativeProbability is not a key, the ceilingEntry is returned instead.
      Specified by:
      getNextEntry in interface EmpiricalDistributionInterface
      Parameters:
      cumulativeProbability - double; the cumulative probability to look up
      Returns:
      DistributionEntry; the first entry object with the probability and corresponding value above (but not at) the provided cumulative probability. Return null when the cumulative probability is larger than the highest cumulative probability
    • getFloorEntryForValue

      public DistributionEntry getFloorEntryForValue(Number value)
      Return the cumulative probability and number below or at the given value, or null when the value is smaller than the lowest value in the distribution.
      Specified by:
      getFloorEntryForValue in interface EmpiricalDistributionInterface
      Parameters:
      value - Number; the value to look up
      Returns:
      DistributionEntry; an entry object with the probability and corresponding value below or at the provided cumulative probability. Return null when the cumulative probability is smaller than the lowest cumulative probability
    • getCeilingEntryForValue

      public DistributionEntry getCeilingEntryForValue(Number value)
      Return the cumulative probability and number above or at the given value, or null when the value is larger than the highest value in the distribution.
      Specified by:
      getCeilingEntryForValue in interface EmpiricalDistributionInterface
      Parameters:
      value - Number; the value to look up
      Returns:
      DistributionEntry; an entry object with the probability and corresponding value above or at the provided cumulative probability. Return null when the cumulative probability is larger than the highest cumulative probability
    • getLowestValue

      public Number getLowestValue()
      Return the lowest value that this empirical distribution can return.
      Specified by:
      getLowestValue in interface EmpiricalDistributionInterface
      Returns:
      Number; the lowest value that this empirical distribution can return
    • getHighestValue

      public Number getHighestValue()
      Return the highest value that this empirical distribution can return.
      Specified by:
      getHighestValue in interface EmpiricalDistributionInterface
      Returns:
      Number; the highest value that this empirical distribution can return
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object