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 Weibull distribution. For more information on this distribution see <a
16 * href="http://mathworld.wolfram.com/WeibullDistribution.html">
17 * http://mathworld.wolfram.com/WeibullDistribution.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.6 2004-03-22
31 * @since 1.2
32 */
33 public class DistWeibull extends DistContinuous
34 {
35 /*** alpha is the alpha parameter */
36 private double alpha;
37
38 /*** beta is the beta parameter */
39 private double beta;
40
41 /***
42 * constructs a new Weibull distribution
43 *
44 * @param stream the numberstream
45 * @param alpha (shape)
46 * @param beta (scale)
47 */
48 public DistWeibull(final StreamInterface stream, final double alpha,
49 final double beta)
50 {
51 super(stream);
52 if ((alpha > 0.0) && (beta > 0.0))
53 {
54 this.alpha = alpha;
55 this.beta = beta;
56 } else
57 {
58 throw new IllegalArgumentException(
59 "Error Weibull - alpha <= 0.0 or beta <= 0.0");
60 }
61 }
62
63 /***
64 * @see DistContinuous#draw()
65 */
66 public double draw()
67 {
68 return this.beta
69 * Math.pow(-Math.log(this.stream.nextDouble()),
70 1.0d / this.alpha);
71 }
72
73 /***
74 * @see nl.tudelft.simulation.jstats.distributions.DistContinuous
75 * #probDensity(double)
76 */
77 public double probDensity(final double observation)
78 {
79 if (observation > 0)
80 {
81 return this.alpha
82 * Math.pow(this.beta, -this.alpha)
83 * Math.pow(observation, this.alpha - 1)
84 * Math.exp(Math.pow(-1 * (observation / this.beta),
85 this.alpha));
86 }
87 return 0.0;
88 }
89
90 /***
91 * @see java.lang.Object#toString()
92 */
93 public String toString()
94 {
95 return "Weibull(" + this.alpha + "," + this.beta + ")";
96 }
97 }