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-2025 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/dsol/manual/" target="_blank">DSOL Manual</a>. The DSOL 17 * project is distributed under a three-clause BSD-style license, which can be found at 18 * <a href="https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">DSOL License</a>. 19 * </p> 20 * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a> 21 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a> 22 */ 23 public class DistExponential extends DistContinuous 24 { 25 /** */ 26 private static final long serialVersionUID = 1L; 27 28 /** mean is the mean value of the exponential distribution. */ 29 private final double mean; 30 31 /** 32 * constructs a new exponential function. The exponential distribution describes the interarrival times of entities to a 33 * system that occur randomly at a constant rate. The exponential distribution can also be characterized by this rate 34 * parameter λ; mean = 1 / λ. 35 * @param stream StreamInterface; the random number stream 36 * @param mean double; the mean (mean > 0) value of the exponential distribution. The exponential distribution can also 37 * be characterized by the rate parameter λ; mean = 1 / λ 38 * @throws IllegalArgumentException in case mean <= 0 39 */ 40 public DistExponential(final StreamInterface stream, final double mean) 41 { 42 super(stream); 43 Throw.when(mean <= 0.0, IllegalArgumentException.class, "Error Exponential - mean<=0"); 44 this.mean = mean; 45 } 46 47 @Override 48 public double draw() 49 { 50 return -this.mean * Math.log(this.stream.nextDouble()); 51 } 52 53 @Override 54 public double getProbabilityDensity(final double x) 55 { 56 if (x >= 0) 57 { 58 return (1 / this.mean) * Math.exp(-x / this.mean); 59 } 60 return 0.0; 61 } 62 63 /** 64 * @return mean 65 */ 66 public double getMean() 67 { 68 return this.mean; 69 } 70 71 @Override 72 public String toString() 73 { 74 return "Exponential(" + this.mean + ")"; 75 } 76 }