Class ProbabilityDensities
For a discrete (non-interpolated) distribution, the code is pretty straightforward, as the cumulative distribution is a step function that changes at the given values. Say, that we have an array of 4 values: {1, 2, 3, 5} and probability densities {0.1, 0.4, 0.3, 0.2}. The cumulative distribution function belonging to these densities is (as value, cumulative probability pairs): {(1, 0.1), (2, 0.5), (3, 0.8), (5, 1.0)}, which is a perfect cumulative distribution function for a Discrete distribution, albeit with floating point values.
For the interpolated version, it is a bit trickier, since it is not totally intuitive how to interpolate when the value array or list and the density array or list have the same length. Say, that we have an array of 4 values: {1, 2, 3, 5} and probability densities {0.1, 0.4, 0.3, 0.2}.
Copyright (c) 2021-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information DSOL Manual. The DSOL project is distributed under a three-clause BSD-style license, which can be found at DSOL License.
- Author:
- Alexander Verbraeck
-
Method Summary
Modifier and TypeMethodDescriptioncreateDiscreteDistribution
(double[] values, double[] probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), from two arrays, one with values, and one with corresponding densities (summing to 1.0).createDiscreteDistribution
(long[] values, double[] probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), from two arrays, one with values, and one with corresponding probabilities (summing to 1.0).createDiscreteDistribution
(Number[] values, double[] probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), from two arrays, one with values, and one with corresponding probabilities (summing to 1.0).createDiscreteDistribution
(List<? extends Number> values, List<Double> probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), based on two Lists of the same length, one with probability probabilities, and one with sorted values.createDiscreteDistribution
(SortedMap<? extends Number, Double> densitiesMap) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), based on a sorted map with sorted values mapping to probability densities.createInterpolatedDistribution
(double[] values, double[] densities) Create a continuous empirical distribution, where the density for index i indicates thatcreateInterpolatedDistribution
(long[] values, double[] densities) Create a continuous empirical distribution, where the density for index i indicates thatcreateInterpolatedDistribution
(Number[] values, double[] densities) Create a continuous empirical distribution, where the density for index i indicates thatcreateInterpolatedDistribution
(List<? extends Number> values, List<Double> densities) Create a continuous empirical distribution, where the density for index i indicates that
-
Method Details
-
createDiscreteDistribution
public static DiscreteEmpiricalDistribution createDiscreteDistribution(Number[] values, double[] probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), from two arrays, one with values, and one with corresponding probabilities (summing to 1.0).- Parameters:
values
- Number[] the valuesprobabilities
- double[]; the probabilities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution arrays
- Throws:
NullPointerException
- when probabilities array is null or values array is null, or when one of the values is nullIllegalArgumentException
- when the probabilities array or values array are empty, or have unequal length, or when probabilities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probabilities is not 1.0
-
createInterpolatedDistribution
public static InterpolatedEmpiricalDistribution createInterpolatedDistribution(Number[] values, double[] densities) Create a continuous empirical distribution, where the density for index i indicates thatF(value[i+1]) - F(value[i]) = density(i)
where F(x) is the cumulative distribution function. The empirical distribution is created from two arrays, one with values, and one with corresponding densities The values array has a length that is one more than the length of the densities array. The densities should be such that:Σ {(value[i+1] - value[i]) * density[i]} = 1.0
- Parameters:
values
- Number[] the valuesdensities
- double[]; the densities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution arrays
- Throws:
NullPointerException
- when densities array is null or values array is null, or when one of the values is nullIllegalArgumentException
- when densities array or values array are empty, or when values.length != (densities.length + 1), or when densities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probability densities times the value intervals is not 1.0
-
createDiscreteDistribution
public static DiscreteEmpiricalDistribution createDiscreteDistribution(double[] values, double[] probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), from two arrays, one with values, and one with corresponding densities (summing to 1.0).- Parameters:
values
- double[] the valuesprobabilities
- double[]; the probabilities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution arrays
- Throws:
NullPointerException
- when probabilities array is null or values array is null, or when one of the values is nullIllegalArgumentException
- when probabilities array or values array are empty, or have unequal length, or when probabilities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probabilities is not 1.0
-
createInterpolatedDistribution
public static InterpolatedEmpiricalDistribution createInterpolatedDistribution(double[] values, double[] densities) Create a continuous empirical distribution, where the density for index i indicates thatF(value[i+1]) - F(value[i]) = density(i)
where F(x) is the cumulative distribution function. The empirical distribution is created from two arrays, one with values, and one with corresponding densities The values array has a length that is one more than the length of the densities array. The densities should be such that:Σ {(value[i+1] - value[i]) * density[i]} = 1.0
- Parameters:
values
- double[] the valuesdensities
- double[]; the densities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution arrays
- Throws:
NullPointerException
- when densities array is null or values array is null, or when one of the values is nullIllegalArgumentException
- when densities array or values array are empty, or when values.length != (densities.length + 1), or when densities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probability densities times the value intervals is not 1.0
-
createDiscreteDistribution
public static DiscreteEmpiricalDistribution createDiscreteDistribution(long[] values, double[] probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), from two arrays, one with values, and one with corresponding probabilities (summing to 1.0).- Parameters:
values
- long[] the valuesprobabilities
- double[]; the probabilities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution arrays
- Throws:
NullPointerException
- when probabilities array is null or values array is null, or when one of the values is nullIllegalArgumentException
- when probabilities array or values array are empty, or have unequal length, or when probabilities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probabilities is not 1.0
-
createInterpolatedDistribution
public static InterpolatedEmpiricalDistribution createInterpolatedDistribution(long[] values, double[] densities) Create a continuous empirical distribution, where the density for index i indicates thatF(value[i+1]) - F(value[i]) = density(i)
where F(x) is the cumulative distribution function. The empirical distribution is created from two arrays, one with values, and one with corresponding densities The values array has a length that is one more than the length of the densities array. The densities should be such that:Σ {(value[i+1] - value[i]) * density[i]} = 1.0
- Parameters:
values
- long[] the valuesdensities
- double[]; the densities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution arrays
- Throws:
NullPointerException
- when densities array is null or values array is null, or when one of the values is nullIllegalArgumentException
- when densities array or values array are empty, or when values.length != (densities.length + 1), or when densities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probability densities times the value intervals is not 1.0
-
createDiscreteDistribution
public static DiscreteEmpiricalDistribution createDiscreteDistribution(List<? extends Number> values, List<Double> probabilities) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), based on two Lists of the same length, one with probability probabilities, and one with sorted values.- Parameters:
values
- List<? extends Number>; the valuesprobabilities
- List<Double>; the probability probabilities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution lists
- Throws:
NullPointerException
- when probabilities list is null or values list is null, or when one of the values is nullIllegalArgumentException
- when probabilities list or values list are empty, or have unequal length, or when probabilities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probabilities is not 1.0
-
createInterpolatedDistribution
public static InterpolatedEmpiricalDistribution createInterpolatedDistribution(List<? extends Number> values, List<Double> densities) Create a continuous empirical distribution, where the density for index i indicates thatF(value[i+1]) - F(value[i]) = density(i)
where F(x) is the cumulative distribution function. The empirical distribution is created from two lists, one with values, and one with corresponding densities The values list has a length that is one more than the length of the densities list. The densities should be such that:Σ {(value[i+1] - value[i]) * density[i]} = 1.0
- Parameters:
values
- List<? extends Number>; the valuesdensities
- List<Double>; the probability densities for the corresponding values- Returns:
- the cumulative distribution object belonging to the given distribution lists
- Throws:
NullPointerException
- when densities list is null or values list is null, or when one of the values is nullIllegalArgumentException
- when densities list or values list are empty, or when values.length != (densities.length + 1), or when densities are not between 0 and 1, or when values are not in ascending order, or when the sum of the probability densities times the value intervals is not 1.0
-
createDiscreteDistribution
public static DiscreteEmpiricalDistribution createDiscreteDistribution(SortedMap<? extends Number, Double> densitiesMap) Create a discrete empirical distribution, where the probabilities for a value indicate P(value), based on a sorted map with sorted values mapping to probability densities.- Parameters:
densitiesMap
- SortedMap<? extends Number, Double>; the map with the entries- Returns:
- the cumulative distribution object belonging to the given distribution map
- Throws:
NullPointerException
- when densities map is null, or when one of the values or densities is nullIllegalArgumentException
- when densities map is empty, or when densities are not between 0 and 1, or when the sum of the probability densities is not 1.0
-