View Javadoc

1   /*
2    * @(#)DistPearson6.java Apr 3, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.jstats.distributions;
11  
12  import cern.jet.stat.Gamma;
13  import nl.tudelft.simulation.jstats.streams.StreamInterface;
14  
15  /***
16   * The Pearson6 distribution. For more information on this distribution see <a
17   * href="http://mathworld.wolfram.com/Pearson6Distribution.html">
18   * http://mathworld.wolfram.com/Pearson6Distribution.html </a>
19   * <p>
20   * (c) copyright 2002-2004 <a href="http://www.simulation.tudelft.nl">Delft
21   * University of Technology </a>, the Netherlands. <br>
22   * See for project information <a href="http://www.simulation.tudelft.nl">
23   * www.simulation.tudelft.nl </a> <br>
24   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
25   * License (GPL) </a>, no warranty <br>
26   * 
27   * @author <a href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">
28   *         Alexander Verbraeck </a> <br>
29   *         <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm"> Peter
30   *         Jacobs </a>
31   * @version 1.9 2004-03-22
32   * @since 1.2
33   */
34  public class DistPearson6 extends DistContinuous
35  {
36  	/*** dist1 is the first gamma distribution */
37  	private DistGamma dist1;
38  
39  	/*** dist2 is the second gamma distribution */
40  	private DistGamma dist2;
41  
42  	/*** alpha1 is the first shape parameter */
43  	private double alpha1;
44  
45  	/*** alpha2 is the second shape parameter */
46  	private double alpha2;
47  
48  	/*** beta is the scale parameter */
49  	private double beta;
50  
51  	/***
52  	 * constructs a new Pearson5 distribution
53  	 * 
54  	 * @param stream the numberstream
55  	 * @param alpha1 the first shape parameter
56  	 * @param alpha2 the second shape parameter
57  	 * @param beta the scale parameter
58  	 */
59  	public DistPearson6(final StreamInterface stream, final double alpha1,
60  			final double alpha2, final double beta)
61  	{
62  		super(stream);
63  		if ((alpha1 > 0.0) && (alpha2 > 0.0) && (beta > 0.0))
64  		{
65  			this.alpha1 = alpha1;
66  			this.alpha2 = alpha2;
67  			this.beta = beta;
68  		} else
69  		{
70  			throw new IllegalArgumentException(
71  					"Error alpha1 <= 0.0 or alpha2 <= 0.0 or beta <= 0.0");
72  		}
73  		this.dist1 = new DistGamma(super.stream, this.alpha1, this.beta);
74  		this.dist2 = new DistGamma(super.stream, this.alpha2, this.beta);
75  	}
76  
77  	/***
78  	 * @see DistContinuous#draw()
79  	 */
80  	public double draw()
81  	{
82  		// according to Law and Kelton, Simulation Modeling and Analysis, 1991
83  		// page 494
84  		return this.dist1.draw() / this.dist2.draw();
85  	}
86  
87  	/***
88  	 * @see nl.tudelft.simulation.jstats.distributions.DistContinuous
89  	 *      #probDensity(double)
90  	 */
91  	public double probDensity(final double observation)
92  	{
93  		if (observation > 0)
94  		{
95  			return Math.pow(observation / this.beta, this.alpha1 - 1)
96  					/ (this.beta * Gamma.beta(this.alpha1, this.alpha2) * Math
97  							.pow(1 + (observation / this.beta),
98  									(this.alpha1 + this.alpha2)));
99  		}
100 		return 0;
101 	}
102 
103 	/***
104 	 * @see java.lang.Object#toString()
105 	 */
106 	public String toString()
107 	{
108 		return "Pesrson6(" + this.alpha1 + "," + this.alpha2 + "," + this.beta
109 				+ ")";
110 	}
111 }