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 LogNormal distribution. For more information on this distribution see <a
16 * href="http://mathworld.wolfram.com/LogNormalDistribution.html">
17 * http://mathworld.wolfram.com/LogNormalDistribution.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.8 2004-03-22
31 * @since 1.2
32 */
33 public class DistLogNormal extends DistNormal
34 {
35 /***
36 * constructs a new logaritmic normal distribution
37 *
38 * @param stream the numberStream
39 * @param mu the medium
40 * @param sigma the standard deviation
41 */
42 public DistLogNormal(final StreamInterface stream, final double mu,
43 final double sigma)
44 {
45 super(stream);
46 this.mu = mu;
47 if (sigma > 0.0)
48 {
49 this.sigma = sigma;
50 } else
51 {
52 throw new IllegalArgumentException(
53 "Error DistLogNormal - sigma<=0.0");
54 }
55 }
56
57 /***
58 * @see DistContinuous#draw()
59 */
60 public double draw()
61 {
62 double y = this.mu + this.sigma * super.nextGaussian();
63 return Math.exp(y);
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
75 / (observation * Math.sqrt(2 * Math.PI
76 * Math.pow(this.sigma, 2)))
77 * Math.exp(-1
78 * Math.pow(Math.log(observation) - this.mu, 2)
79 / (2 * Math.pow(this.sigma, 2)));
80 }
81 return 0.0;
82 }
83
84 /***
85 * @see java.lang.Object#toString()
86 */
87 public String toString()
88 {
89 return "LogNormal(" + this.mu + "," + this.sigma + ")";
90 }
91 }