1 | package de.uka.ipd.sdq.simucomframework.variables.functions; |
2 | |
3 | import java.util.List; |
4 | |
5 | |
6 | import de.uka.ipd.sdq.probfunction.math.ILognormalDistribution; |
7 | import de.uka.ipd.sdq.probfunction.math.IPDFFactory; |
8 | import de.uka.ipd.sdq.probfunction.math.IRandomGenerator; |
9 | import de.uka.ipd.sdq.simucomframework.variables.converter.NumberConverter; |
10 | |
11 | /** |
12 | * Lognormal distribution from the distributions moments: Parameters mean and standard deviation. |
13 | * @author Anne |
14 | * |
15 | */ |
16 | public class LogNormDistFunctionFromMoments extends AbstractProbDistFunction { |
17 | |
18 | |
19 | public LogNormDistFunctionFromMoments(IRandomGenerator random, IPDFFactory factory) { |
20 | super(random, factory); |
21 | } |
22 | |
23 | /** |
24 | * Checks the validity of the parameter. |
25 | * LognormFromMoments takes two parameters mean and standard deviation |
26 | * mean needs to be larger than 0. |
27 | * stdev needs to be larger than 0. |
28 | */ |
29 | public boolean checkParameters(List<Object> parameters) { |
30 | //two parameters mean and c |
31 | if (parameters.size() != 2) |
32 | return false; |
33 | //mean needs to be larger than 0. |
34 | if (NumberConverter.toDouble(parameters.get(0)) < 0) |
35 | return false; |
36 | //stdev needs to be larger than 0. |
37 | if (NumberConverter.toDouble(parameters.get(1)) < 0) |
38 | return false; |
39 | return true; |
40 | } |
41 | |
42 | public Object evaluate(List<Object> parameters) { |
43 | double mean = NumberConverter.toDouble(parameters.get(0)); |
44 | double stdev = NumberConverter.toDouble(parameters.get(1)); |
45 | double variance = stdev*stdev; |
46 | ILognormalDistribution distribution = factory.createLognormalDistributionFromMoments(mean, variance); |
47 | return distribution.inverseF(randomGen.random()); |
48 | } |
49 | |
50 | } |