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
ConstructorDescriptionAbstractEmpiricalDistribution
(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 TypeMethodDescriptionboolean
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).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.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.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.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
hashCode()
int
size()
Returns the number of probability-value mappings in this structure.toString()
-
Constructor Details
-
AbstractEmpiricalDistribution
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 probabilitycumulativeProbabilities
- double[]; the cumulative probabilities- Throws:
NullPointerException
- when one of the values is nullIllegalArgumentException
- 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 interfaceEmpiricalDistributionInterface
- Returns:
- int; the number of probability-value mappings in this structure.
-
getCumulativeProbabilities
Returns the cumulative probabilities as a list.- Specified by:
getCumulativeProbabilities
in interfaceEmpiricalDistributionInterface
- Returns:
- the list of cumulative probabilities
-
getValues
Returns the values as a list.- Specified by:
getValues
in interfaceEmpiricalDistributionInterface
- Returns:
- the list of values
-
getFloorEntry
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 interfaceEmpiricalDistributionInterface
- 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
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 interfaceEmpiricalDistributionInterface
- 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
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 interfaceEmpiricalDistributionInterface
- 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
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 interfaceEmpiricalDistributionInterface
- 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
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 interfaceEmpiricalDistributionInterface
- 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
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 interfaceEmpiricalDistributionInterface
- 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
Return the lowest value that this empirical distribution can return.- Specified by:
getLowestValue
in interfaceEmpiricalDistributionInterface
- Returns:
- Number; the lowest value that this empirical distribution can return
-
getHighestValue
Return the highest value that this empirical distribution can return.- Specified by:
getHighestValue
in interfaceEmpiricalDistributionInterface
- Returns:
- Number; the highest value that this empirical distribution can return
-
hashCode
public int hashCode() -
equals
-
toString
-