Class ProbabilityDensities

java.lang.Object
nl.tudelft.simulation.jstats.distributions.empirical.ProbabilityDensities

public final class ProbabilityDensities extends Object
ProbabilityDensities is a helper class to instantiate interpolated and non-interpolated distributions based on a given array or list of values and corresponding probability densities.

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 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 values
      probabilities - 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 null
      IllegalArgumentException - 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 that
          F(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 values
      densities - 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 null
      IllegalArgumentException - 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 values
      probabilities - 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 null
      IllegalArgumentException - 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 that
          F(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 values
      densities - 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 null
      IllegalArgumentException - 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 values
      probabilities - 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 null
      IllegalArgumentException - 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 that
          F(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 values
      densities - 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 null
      IllegalArgumentException - 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 values
      probabilities - 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 null
      IllegalArgumentException - 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 that
          F(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 values
      densities - 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 null
      IllegalArgumentException - 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 null
      IllegalArgumentException - 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