1 | package de.uka.ipd.sdq.simucomframework.variables.functions; |
2 | |
3 | import java.util.List; |
4 | |
5 | import de.uka.ipd.sdq.probfunction.math.IGammaDistribution; |
6 | import de.uka.ipd.sdq.probfunction.math.IPDFFactory; |
7 | import de.uka.ipd.sdq.probfunction.math.IRandomGenerator; |
8 | |
9 | import de.uka.ipd.sdq.simucomframework.variables.converter.NumberConverter; |
10 | |
11 | /** |
12 | * Gamma distribution with shape alpha > 0 and inverse scale parameter beta > 0 |
13 | * There is another way to write the gamma function with k = alpha and theta = 1/beta, |
14 | * @author Anne |
15 | * |
16 | */ |
17 | public class GammaDistFunctionFromMoments extends AbstractProbDistFunction { |
18 | |
19 | |
20 | public GammaDistFunctionFromMoments(IRandomGenerator randomGen, IPDFFactory factory) { |
21 | super(randomGen, factory); |
22 | } |
23 | |
24 | /** |
25 | * Checks the validity of the parameter. |
26 | * GammaDistFunctionFromMoments takes |
27 | * two parameters mean and c coefficient of variance |
28 | * mean needs to be larger than 0. |
29 | * c needs to be larger than 0. |
30 | */ |
31 | public boolean checkParameters(List<Object> parameters) { |
32 | //two parameters mean and c |
33 | if (parameters.size() != 2) |
34 | return false; |
35 | //mean needs to be larger than 0. |
36 | if (NumberConverter.toDouble(parameters.get(0)) < 0) |
37 | return false; |
38 | //c needs to be larger than 0. |
39 | if (NumberConverter.toDouble(parameters.get(1)) < 0) |
40 | return false; |
41 | return true; |
42 | } |
43 | |
44 | public Object evaluate(List<Object> parameters) { |
45 | double mean = NumberConverter.toDouble(parameters.get(0)); |
46 | double coeffVar = NumberConverter.toDouble(parameters.get(1)); |
47 | |
48 | IGammaDistribution distribution = factory.createGammaDistributionFromMoments(mean, coeffVar); |
49 | return distribution.inverseF(randomGen.random()); |
50 | } |
51 | |
52 | } |