1 package nl.tudelft.simulation.jstats.distributions; 2 3 import org.djutils.exceptions.Throw; 4 5 import nl.tudelft.simulation.jstats.streams.StreamInterface; 6 7 /** 8 * The Exponential distribution. For more information on this distribution see 9 * <a href="https://mathworld.wolfram.com/ExponentialDistribution.html"> 10 * https://mathworld.wolfram.com/ExponentialDistribution.html </a><br> 11 * The exponential distribution describes the interarrival times of entities to a system that occur randomly at a constant rate. 12 * The exponential distribution here is characterized by the mean interarrival time, but can also be characterized by this rate 13 * parameter λ; mean = 1 / λ. 14 * <p> 15 * Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See 16 * for project information <a href="https://simulation.tudelft.nl/" target="_blank"> https://simulation.tudelft.nl</a>. The DSOL 17 * project is distributed under a three-clause BSD-style license, which can be found at 18 * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank"> 19 * https://https://simulation.tudelft.nl/dsol/docs/latest/license.html</a>. 20 * </p> 21 * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a> 22 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a> 23 */ 24 public class DistExponential extends DistContinuous 25 { 26 /** */ 27 private static final long serialVersionUID = 1L; 28 29 /** mean is the mean value of the exponential distribution. */ 30 private final double mean; 31 32 /** 33 * constructs a new exponential function. The exponential distribution describes the interarrival times of entities to a 34 * system that occur randomly at a constant rate. The exponential distribution can also be characterized by this rate 35 * parameter λ; mean = 1 / λ. 36 * @param stream StreamInterface; the random number stream 37 * @param mean double; the mean (mean > 0) value of the exponential distribution. The exponential distribution can also 38 * be characterized by the rate parameter λ; mean = 1 / λ 39 * @throws IllegalArgumentException in case mean <= 0 40 */ 41 public DistExponential(final StreamInterface stream, final double mean) 42 { 43 super(stream); 44 Throw.when(mean <= 0.0, IllegalArgumentException.class, "Error Exponential - mean<=0"); 45 this.mean = mean; 46 } 47 48 /** {@inheritDoc} */ 49 @Override 50 public double draw() 51 { 52 return -this.mean * Math.log(this.stream.nextDouble()); 53 } 54 55 /** {@inheritDoc} */ 56 @Override 57 public double getProbabilityDensity(final double x) 58 { 59 if (x >= 0) 60 { 61 return (1 / this.mean) * Math.exp(-x / this.mean); 62 } 63 return 0.0; 64 } 65 66 /** 67 * @return mean 68 */ 69 public double getMean() 70 { 71 return this.mean; 72 } 73 74 /** {@inheritDoc} */ 75 @Override 76 public String toString() 77 { 78 return "Exponential(" + this.mean + ")"; 79 } 80 }