1 package nl.tudelft.simulation.jstats.distributions;
2
3 import org.djutils.exceptions.Throw;
4
5 import nl.tudelft.simulation.jstats.math.ProbMath;
6 import nl.tudelft.simulation.jstats.streams.StreamInterface;
7
8 /**
9 * The Pearson5 distribution with a shape parameter α and a scale parameter β. The distribution is sometimes called
10 * the inverse gamma distribution, because if X ~ PT5(α, β) if and only if Y = 1 / X ~ gamma(α, 1/β). For
11 * more information on this distribution see <a href="https://en.wikipedia.org/wiki/Inverse-gamma_distribution">
12 * https://en.wikipedia.org/wiki/Inverse-gamma_distribution</a>
13 * <p>
14 * Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
15 * for project information <a href="https://simulation.tudelft.nl/" target="_blank"> https://simulation.tudelft.nl</a>. The DSOL
16 * project is distributed under a three-clause BSD-style license, which can be found at
17 * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank">
18 * https://https://simulation.tudelft.nl/dsol/docs/latest/license.html</a>.
19 * </p>
20 * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a>
21 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22 */
23 public class DistPearson5 extends DistContinuous
24 {
25 /** */
26 private static final long serialVersionUID = 1L;
27
28 /** dist is the internal gamma distribution for calculation. */
29 private final DistGamma dist;
30
31 /** alpha is the shape parameter α of the distribution. */
32 private final double alpha;
33
34 /** beta is the scale parameter β of the distribution. */
35 private final double beta;
36
37 /**
38 * constructs a new Pearson5 distribution.
39 * @param stream StreamInterface; the random number stream
40 * @param alpha double; the shape parameter α of the distribution
41 * @param beta double; the scale parameter β of the distribution
42 * @throws IllegalArgumentException when alpha <= 0 or beta <= 0
43 */
44 public DistPearson5(final StreamInterface stream, final double alpha, final double beta)
45 {
46 super(stream);
47 Throw.when(alpha <= 0.0 || beta <= 0.0, IllegalArgumentException.class,
48 "Pearson5 distribution cannot be created with alpha <= 0.0 or beta <= 0.0");
49 this.alpha = alpha;
50 this.beta = beta;
51 this.dist = new DistGamma(stream, this.alpha, 1.0d / this.beta);
52 }
53
54 /** {@inheritDoc} */
55 @Override
56 public double draw()
57 {
58 // according to Law and Kelton, Simulation Modeling and Analysis, 1991 pages 492-493
59 return 1.0d / this.dist.draw();
60 }
61
62 /** {@inheritDoc} */
63 @Override
64 public double getProbabilityDensity(final double x)
65 {
66 if (x > 0)
67 {
68 return Math.pow(this.beta, this.alpha) * Math.pow(x, -this.alpha - 1) * Math.exp(-this.beta / x)
69 / ProbMath.gamma(this.alpha);
70 }
71 return 0;
72 }
73
74 /**
75 * Return the shape parameter α of the distribution.
76 * @return double; the shape parameter α of the distribution
77 */
78 public double getAlpha()
79 {
80 return this.alpha;
81 }
82
83 /**
84 * Return the scale parameter β of the distribution.
85 * @return double; the scale parameter β of the distribution
86 */
87 public double getBeta()
88 {
89 return this.beta;
90 }
91
92 /** {@inheritDoc} */
93 @Override
94 public void setStream(final StreamInterface stream)
95 {
96 super.setStream(stream);
97 this.dist.setStream(stream);
98 }
99
100 /** {@inheritDoc} */
101 @Override
102 public String toString()
103 {
104 return "Pearson5(" + this.alpha + "," + this.beta + ")";
105 }
106 }