| 1 | package de.uka.ipd.sdq.probfunction.math.apache.impl; |
| 2 | |
| 3 | import org.apache.commons.math.MathException; |
| 4 | |
| 5 | import de.uka.ipd.sdq.probfunction.math.apache.distribution.LognormalDistributionFromMomentsImpl; |
| 6 | import de.uka.ipd.sdq.probfunction.math.apache.distribution.LognormalDistributionImpl; |
| 7 | //import umontreal.iro.lecuyer.probdist.LognormalDist; |
| 8 | //import umontreal.iro.lecuyer.probdist.LognormalDistFromMoments; |
| 9 | import de.uka.ipd.sdq.probfunction.math.ILognormalDistribution; |
| 10 | import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction; |
| 11 | import de.uka.ipd.sdq.probfunction.math.exception.DomainNotNumbersException; |
| 12 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInFrequencyDomainException; |
| 13 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInTimeDomainException; |
| 14 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionsInDifferenDomainsException; |
| 15 | import de.uka.ipd.sdq.probfunction.math.exception.IncompatibleUnitsException; |
| 16 | import de.uka.ipd.sdq.probfunction.math.exception.InvalidSampleValueException; |
| 17 | import de.uka.ipd.sdq.probfunction.math.exception.NegativeDistanceException; |
| 18 | import de.uka.ipd.sdq.probfunction.math.exception.ProbabilityFunctionException; |
| 19 | import de.uka.ipd.sdq.probfunction.math.exception.ProbabilitySumNotOneException; |
| 20 | import de.uka.ipd.sdq.probfunction.math.exception.UnitNameNotSetException; |
| 21 | import de.uka.ipd.sdq.probfunction.math.exception.UnitNotSetException; |
| 22 | import de.uka.ipd.sdq.probfunction.math.exception.UnknownPDFTypeException; |
| 23 | import de.uka.ipd.sdq.probfunction.math.exception.UnorderedDomainException; |
| 24 | |
| 25 | public class LognormalDistribution extends AbstractContinousPDF implements ILognormalDistribution { |
| 26 | |
| 27 | public LognormalDistribution(double mu, double sigma) { |
| 28 | super(); |
| 29 | this.internalFunction = new LognormalDistributionImpl(mu, sigma); |
| 30 | } |
| 31 | |
| 32 | protected LognormalDistribution(){ |
| 33 | super(); |
| 34 | } |
| 35 | |
| 36 | private LognormalDistribution(LognormalDistributionImpl internal){ |
| 37 | super(); |
| 38 | this.internalFunction = internal; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | @Override |
| 43 | public double cdf(double x) { |
| 44 | //SSJ compatibility |
| 45 | if(x == 0.0) |
| 46 | return 0; |
| 47 | return super.cdf(x); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public double density(double x) { |
| 52 | //SSJ compatibility |
| 53 | if(x == 0.0) |
| 54 | return 0.0; |
| 55 | |
| 56 | return super.density(x); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public double inverseF(double u) |
| 61 | { |
| 62 | //SSJ compatibility |
| 63 | if(u == 0.0) |
| 64 | return 0.0; |
| 65 | return super.inverseF(u); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | |
| 70 | public IProbabilityDensityFunction add(IProbabilityDensityFunction pdf) |
| 71 | throws FunctionsInDifferenDomainsException, |
| 72 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 73 | throw new UnsupportedOperationException(); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | public IProbabilityDensityFunction div(IProbabilityDensityFunction pdf) |
| 78 | throws FunctionsInDifferenDomainsException, |
| 79 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 80 | throw new UnsupportedOperationException(); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | public IProbabilityDensityFunction getCumulativeFunction() |
| 85 | throws FunctionNotInTimeDomainException { |
| 86 | throw new UnsupportedOperationException(); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | public IProbabilityDensityFunction getFourierTransform() |
| 91 | throws FunctionNotInTimeDomainException { |
| 92 | throw new UnsupportedOperationException(); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | public IProbabilityDensityFunction getInverseFourierTransform() |
| 97 | throws FunctionNotInFrequencyDomainException { |
| 98 | throw new UnsupportedOperationException(); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | public double getLowerDomainBorder() { |
| 103 | throw new UnsupportedOperationException(); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | public double greaterThan(IProbabilityDensityFunction pdf) |
| 108 | throws ProbabilityFunctionException { |
| 109 | throw new UnsupportedOperationException(); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | public double lessThan(IProbabilityDensityFunction pdf) |
| 114 | throws ProbabilityFunctionException { |
| 115 | throw new UnsupportedOperationException(); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | public IProbabilityDensityFunction mult(IProbabilityDensityFunction pdf) |
| 120 | throws FunctionsInDifferenDomainsException, |
| 121 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 122 | throw new UnsupportedOperationException(); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | public double probabilisticEquals(IProbabilityDensityFunction pdf) |
| 127 | throws ProbabilityFunctionException { |
| 128 | throw new UnsupportedOperationException(); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | public IProbabilityDensityFunction scale(double scalar) { |
| 133 | throw new UnsupportedOperationException(); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | public IProbabilityDensityFunction sub(IProbabilityDensityFunction pdf) |
| 138 | throws FunctionsInDifferenDomainsException, |
| 139 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 140 | throw new UnsupportedOperationException(); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | public void checkConstrains() throws NegativeDistanceException, |
| 145 | ProbabilitySumNotOneException, FunctionNotInTimeDomainException, |
| 146 | UnitNotSetException, UnitNameNotSetException, |
| 147 | InvalidSampleValueException { |
| 148 | throw new UnsupportedOperationException(); |
| 149 | |
| 150 | } |
| 151 | |
| 152 | |
| 153 | public Object getMedian() throws UnorderedDomainException { |
| 154 | throw new UnsupportedOperationException(); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | public Object getPercentile(int p) throws IndexOutOfBoundsException, |
| 159 | UnorderedDomainException { |
| 160 | throw new UnsupportedOperationException(); |
| 161 | } |
| 162 | |
| 163 | public boolean hasOrderedDomain() { |
| 164 | throw new UnsupportedOperationException(); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | public double getMu() { |
| 169 | return ((LognormalDistributionImpl)this.internalFunction).getMean(); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | public double getSigma() { |
| 174 | return ((LognormalDistributionImpl)this.internalFunction).getStandardDeviation(); |
| 175 | } |
| 176 | |
| 177 | |
| 178 | public IProbabilityDensityFunction shiftDomain(double scalar) |
| 179 | throws DomainNotNumbersException { |
| 180 | double newMean = this.getArithmeticMeanValue() + scalar; |
| 181 | double newVariance = this.getVariance(); |
| 182 | try { |
| 183 | return new LognormalDistribution(new LognormalDistributionFromMomentsImpl(newMean, newVariance)); |
| 184 | } catch (MathException e) { |
| 185 | throw new ProbabilityFunctionException(e.getLocalizedMessage()); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | |
| 190 | public IProbabilityDensityFunction stretchDomain(double scalar) { |
| 191 | double newMean = this.getArithmeticMeanValue() * scalar; |
| 192 | double newVariance = this.getVariance() * scalar * scalar; |
| 193 | try { |
| 194 | return new LognormalDistribution(new LognormalDistributionFromMomentsImpl(newMean, newVariance)); |
| 195 | } catch (MathException e) { |
| 196 | throw new ProbabilityFunctionException(e.getLocalizedMessage()); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public double getStandardDeviation() { |
| 202 | return Math.sqrt(getVariance()); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public double getXinf() { |
| 207 | return 0.0; |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public double getXsup() { |
| 212 | return Double.POSITIVE_INFINITY; |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public double getArithmeticMeanValue() throws DomainNotNumbersException, |
| 217 | FunctionNotInTimeDomainException { |
| 218 | double sigma = getSigma(); |
| 219 | double sigma2 = sigma*sigma; |
| 220 | double mu = getMu(); |
| 221 | return Math.exp(mu+sigma2/2); |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public double getVariance() { |
| 226 | double sigma = getSigma(); |
| 227 | double sigma2 = sigma*sigma; |
| 228 | double mu = getMu(); |
| 229 | return Math.exp(sigma2 + 2*mu)*Math.expm1(sigma2); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | } |