| 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 | import de.uka.ipd.sdq.simucomframework.variables.converter.NumberConverter; |
| 9 | |
| 10 | /** |
| 11 | * Gamma distribution with shape alpha > 0 and scale parameter theta > 0 |
| 12 | * There is another way to write the gamma function with k = alpha or |
| 13 | * rate parameter beta = 1/theta, |
| 14 | * @author Anne |
| 15 | * |
| 16 | */ |
| 17 | public class GammaDistFunction extends AbstractProbDistFunction { |
| 18 | |
| 19 | |
| 20 | |
| 21 | public GammaDistFunction(IRandomGenerator randomGen, IPDFFactory factory) { |
| 22 | super(randomGen, factory); |
| 23 | } |
| 24 | |
| 25 | public boolean checkParameters(List<Object> parameters) { |
| 26 | //two parameters alpha and theta |
| 27 | if (parameters.size() != 2) |
| 28 | return false; |
| 29 | //alpha needs to be larger than 0. |
| 30 | if (NumberConverter.toDouble(parameters.get(1)) <= 0) |
| 31 | return false; |
| 32 | //theta needs to be larger than 0. |
| 33 | if (NumberConverter.toDouble(parameters.get(0)) <= 0) |
| 34 | return false; |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | public Object evaluate(List<Object> parameters) { |
| 39 | double alpha = NumberConverter.toDouble(parameters.get(0)); |
| 40 | double theta= NumberConverter.toDouble(parameters.get(1)); |
| 41 | //alpha is alpha (also called k), lambda is 1/theta |
| 42 | IGammaDistribution distribution = factory.createGammaDistribution(alpha, theta); |
| 43 | return distribution.inverseF(randomGen.random()); |
| 44 | } |
| 45 | |
| 46 | } |