1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.jstats.distributions;
11
12 import nl.tudelft.simulation.jstats.streams.StreamInterface;
13
14 /***
15 * The Exponential distribution. For more information on this distribution see
16 * <a href="http://mathworld.wolfram.com/ExponentialDistribution.html">
17 * http://mathworld.wolfram.com/ExponentialDistribution.html </a>
18 * <p>
19 * (c) copyright 2002-2004 <a href="http://www.simulation.tudelft.nl">Delft
20 * University of Technology </a>, the Netherlands. <br>
21 * See for project information <a href="http://www.simulation.tudelft.nl">
22 * www.simulation.tudelft.nl </a> <br>
23 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
24 * License (GPL) </a>, no warranty <br>
25 *
26 * @author <a href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">
27 * Alexander Verbraeck </a> <br>
28 * <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm"> Peter
29 * Jacobs </a>
30 * @version 1.10 2004-03-22
31 * @since 1.2
32 */
33 public class DistExponential extends DistContinuous
34 {
35 /*** mean is the mean value of the exponential distribution */
36 private double mean;
37
38 /***
39 * constructs a new exponential function. The exponential distribution
40 * describes the interarrival times of "cutomers" to a system that occur at
41 * a constant rate.
42 *
43 * @param stream the numberstream
44 * @param mean the mean (mean>0)
45 */
46 public DistExponential(final StreamInterface stream, final double mean)
47 {
48 super(stream);
49 if (mean > 0.0)
50 {
51 this.mean = mean;
52 } else
53 {
54 throw new IllegalArgumentException("Error Exponential - mean<=0");
55 }
56 }
57
58 /***
59 * @see DistContinuous#draw()
60 */
61 public double draw()
62 {
63 return -this.mean * Math.log(this.stream.nextDouble());
64 }
65
66 /***
67 * @see nl.tudelft.simulation.jstats.distributions.DistContinuous
68 * #probDensity(double)
69 */
70 public double probDensity(final double observation)
71 {
72 if (observation >= 0)
73 {
74 return (1 / this.mean) * Math.exp(-observation / this.mean);
75 }
76 return 0.0;
77 }
78
79 /***
80 * @see java.lang.Object#toString()
81 */
82 public String toString()
83 {
84 return "Exponential(" + this.mean + ")";
85 }
86 }