| 1 | package de.uka.ipd.sdq.simucomframework.variables.functions; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | import de.uka.ipd.sdq.probfunction.math.ILognormalDistribution; |
| 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 | * Lognormal distribution with parameters scale parameter mu and shape parameter sigma > 0. |
| 12 | * @author Anne |
| 13 | * |
| 14 | */ |
| 15 | public class LogNormDistFunction extends AbstractProbDistFunction { |
| 16 | |
| 17 | |
| 18 | |
| 19 | public LogNormDistFunction(IRandomGenerator randomGen, IPDFFactory factory) { |
| 20 | super(randomGen, factory); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Checks the validity of the parameter. |
| 25 | * Lognorm takes two parameters mu (scale parameter) and sigma (shape parameter) |
| 26 | * sigma needs to be larger than 0. |
| 27 | * mu parameter can be any double |
| 28 | */ |
| 29 | public boolean checkParameters(List<Object> parameters) { |
| 30 | //two parameters mu and sigma |
| 31 | if (parameters.size() != 2) |
| 32 | return false; |
| 33 | //sigma needs to be larger than 0. |
| 34 | if (NumberConverter.toDouble(parameters.get(1)) <= 0) |
| 35 | return false; |
| 36 | //mu parameter can be any double |
| 37 | NumberConverter.toDouble(parameters.get(0)); |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | public Object evaluate(List<Object> parameters) { |
| 42 | double mu = NumberConverter.toDouble(parameters.get(0)); |
| 43 | double sigma= NumberConverter.toDouble(parameters.get(1)); |
| 44 | ILognormalDistribution distribution = factory.createLognormalDistribution(mu, sigma); |
| 45 | return distribution.inverseF(randomGen.random()); |
| 46 | } |
| 47 | |
| 48 | } |