1 | package de.uka.ipd.sdq.probfunction.math.apache.distribution; |
2 | |
3 | import org.apache.commons.math.distribution.GammaDistributionImpl; |
4 | |
5 | /** |
6 | * SDQ implementation of GammaDistFromMoments based on apache.commons.math |
7 | * |
8 | * @author joerg |
9 | * |
10 | */ |
11 | public class GammaDistributionFromMomentsImpl extends GammaDistributionImpl |
12 | { |
13 | /** Serializable version identifier */ |
14 | private static final long serialVersionUID = -6141545702288594591L; |
15 | |
16 | /** |
17 | * Create a new gamma distribution with the given mean and variance values. |
18 | * |
19 | * @param mean The mean value |
20 | * @param variance The variance value |
21 | */ |
22 | public GammaDistributionFromMomentsImpl (double mean, double variance) |
23 | { |
24 | super (calculateAlpha (mean, variance), calculateTheta (mean, variance)); |
25 | } |
26 | |
27 | /** |
28 | * Calculate alpha from mean and variance. |
29 | * mean = alpha*theta |
30 | * |
31 | * alpha = mean/theta |
32 | * |
33 | * @param mean The mean value |
34 | * @param variance The variance value |
35 | * @return alpha The alpha value |
36 | */ |
37 | private static double calculateAlpha (double mean, double variance) { |
38 | // return (mean*mean)/variance; |
39 | return mean/calculateTheta (mean, variance); |
40 | } |
41 | |
42 | /** |
43 | * Calculate theta from mean and variance. |
44 | * variance = alpha*theta2 |
45 | * alpha = mean/theta |
46 | * variance = mean*theta |
47 | * theta = variance/mean |
48 | * |
49 | * @param mean The mean value |
50 | * @param variance The variance value |
51 | * @return theta The theta value |
52 | */ |
53 | private static double calculateTheta (double mean, double variance) { |
54 | |
55 | return variance/mean; |
56 | } |
57 | |
58 | |
59 | |
60 | |
61 | } |