| 1 | package de.uka.ipd.sdq.probfunction.math.apache.impl; |
| 2 | |
| 3 | |
| 4 | import org.apache.commons.math.distribution.NormalDistributionImpl; |
| 5 | //import umontreal.iro.lecuyer.probdist.NormalDist; |
| 6 | import de.uka.ipd.sdq.probfunction.math.INormalDistribution; |
| 7 | import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction; |
| 8 | import de.uka.ipd.sdq.probfunction.math.exception.DomainNotNumbersException; |
| 9 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInFrequencyDomainException; |
| 10 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInTimeDomainException; |
| 11 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionsInDifferenDomainsException; |
| 12 | import de.uka.ipd.sdq.probfunction.math.exception.IncompatibleUnitsException; |
| 13 | import de.uka.ipd.sdq.probfunction.math.exception.InvalidSampleValueException; |
| 14 | import de.uka.ipd.sdq.probfunction.math.exception.NegativeDistanceException; |
| 15 | import de.uka.ipd.sdq.probfunction.math.exception.ProbabilityFunctionException; |
| 16 | import de.uka.ipd.sdq.probfunction.math.exception.ProbabilitySumNotOneException; |
| 17 | import de.uka.ipd.sdq.probfunction.math.exception.UnitNameNotSetException; |
| 18 | import de.uka.ipd.sdq.probfunction.math.exception.UnitNotSetException; |
| 19 | import de.uka.ipd.sdq.probfunction.math.exception.UnknownPDFTypeException; |
| 20 | import de.uka.ipd.sdq.probfunction.math.exception.UnorderedDomainException; |
| 21 | |
| 22 | /** |
| 23 | * TODO: A number of calculations are possible, implement them instead of throwing UnsupportedOperationException(). |
| 24 | * |
| 25 | * See e.g. http://en.wikipedia.org/wiki/List_of_convolutions_of_probability_distributions |
| 26 | * @author martens |
| 27 | * |
| 28 | */ |
| 29 | public class NormalDistribution extends AbstractContinousPDF implements |
| 30 | INormalDistribution { |
| 31 | |
| 32 | public NormalDistribution(double mean, double sigma){ |
| 33 | double sd = sigma; |
| 34 | this.internalFunction = new NormalDistributionImpl(mean, sd); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public double getMean() { |
| 39 | return ((NormalDistributionImpl)this.internalFunction).getMean(); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public double getSigma() { |
| 44 | return ((NormalDistributionImpl)this.internalFunction).getStandardDeviation(); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public IProbabilityDensityFunction add(IProbabilityDensityFunction pdf) |
| 49 | throws FunctionsInDifferenDomainsException, |
| 50 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 51 | throw new UnsupportedOperationException(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public IProbabilityDensityFunction div(IProbabilityDensityFunction pdf) |
| 56 | throws FunctionsInDifferenDomainsException, |
| 57 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 58 | throw new UnsupportedOperationException(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public IProbabilityDensityFunction getCumulativeFunction() |
| 63 | throws FunctionNotInTimeDomainException { |
| 64 | throw new UnsupportedOperationException(); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public IProbabilityDensityFunction getFourierTransform() |
| 69 | throws FunctionNotInTimeDomainException { |
| 70 | throw new UnsupportedOperationException(); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public IProbabilityDensityFunction getInverseFourierTransform() |
| 75 | throws FunctionNotInFrequencyDomainException { |
| 76 | throw new UnsupportedOperationException(); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public double getLowerDomainBorder() { |
| 81 | throw new UnsupportedOperationException(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public double greaterThan(IProbabilityDensityFunction pdf) |
| 86 | throws ProbabilityFunctionException { |
| 87 | throw new UnsupportedOperationException(); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public double lessThan(IProbabilityDensityFunction pdf) |
| 92 | throws ProbabilityFunctionException { |
| 93 | throw new UnsupportedOperationException(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public IProbabilityDensityFunction mult(IProbabilityDensityFunction pdf) |
| 98 | throws FunctionsInDifferenDomainsException, |
| 99 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 100 | throw new UnsupportedOperationException(); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public double probabilisticEquals(IProbabilityDensityFunction pdf) |
| 105 | throws ProbabilityFunctionException { |
| 106 | throw new UnsupportedOperationException(); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public IProbabilityDensityFunction scale(double scalar) { |
| 111 | throw new UnsupportedOperationException(); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | /** |
| 116 | * ``substracting a constant [...] reduces the mean [..] by that constant'' |
| 117 | * Statistical Methods for Psychology Von David C. Howell, p. 72 |
| 118 | */ |
| 119 | public IProbabilityDensityFunction shiftDomain(double scalar) |
| 120 | throws DomainNotNumbersException { |
| 121 | double newMean = this.getArithmeticMeanValue() + scalar; |
| 122 | double newSigma = this.getSigma(); |
| 123 | return new NormalDistribution(newMean, newSigma); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | /** |
| 128 | * ``if we multiply or divide [...] by a constant [..], we multiply of divide the standard deviation by that constant.'' |
| 129 | * and also the mean (in the cited case the mean was 0). |
| 130 | * Statistical Methods for Psychology Von David C. Howell, p. 72 |
| 131 | */ |
| 132 | public IProbabilityDensityFunction stretchDomain(double scalar) { |
| 133 | double newMean = this.getArithmeticMeanValue() * scalar; |
| 134 | double newSigma = this.getSigma() * scalar; |
| 135 | return new NormalDistribution(newMean, newSigma); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public IProbabilityDensityFunction sub(IProbabilityDensityFunction pdf) |
| 140 | throws FunctionsInDifferenDomainsException, |
| 141 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 142 | throw new UnsupportedOperationException(); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void checkConstrains() throws NegativeDistanceException, |
| 147 | ProbabilitySumNotOneException, FunctionNotInTimeDomainException, |
| 148 | UnitNotSetException, UnitNameNotSetException, |
| 149 | InvalidSampleValueException { |
| 150 | // TODO Auto-generated method stub |
| 151 | |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public Object getMedian() throws UnorderedDomainException { |
| 156 | return ((NormalDistributionImpl)internalFunction).getMean(); |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public Object getPercentile(int p) throws IndexOutOfBoundsException, |
| 161 | UnorderedDomainException { |
| 162 | throw new UnsupportedOperationException(); |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public boolean hasOrderedDomain() { |
| 167 | throw new UnsupportedOperationException(); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public double getStandardDeviation() { |
| 172 | return ((NormalDistributionImpl)internalFunction).getStandardDeviation(); |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public double getXinf() { |
| 177 | |
| 178 | return Double.NEGATIVE_INFINITY; |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public double getXsup() { |
| 183 | return Double.POSITIVE_INFINITY; |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public double getArithmeticMeanValue() throws DomainNotNumbersException, |
| 188 | FunctionNotInTimeDomainException { |
| 189 | return ((NormalDistributionImpl)internalFunction).getMean(); |
| 190 | } |
| 191 | |
| 192 | } |