| 1 | package de.uka.ipd.sdq.probfunction.math.apache.impl; |
| 2 | |
| 3 | import org.apache.commons.math.distribution.ExponentialDistributionImpl; |
| 4 | //import umontreal.iro.lecuyer.probdist.ExponentialDist; |
| 5 | import de.uka.ipd.sdq.probfunction.math.IExponentialDistribution; |
| 6 | import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction; |
| 7 | import de.uka.ipd.sdq.probfunction.math.exception.DomainNotNumbersException; |
| 8 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInFrequencyDomainException; |
| 9 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionNotInTimeDomainException; |
| 10 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionsInDifferenDomainsException; |
| 11 | import de.uka.ipd.sdq.probfunction.math.exception.IncompatibleUnitsException; |
| 12 | import de.uka.ipd.sdq.probfunction.math.exception.InvalidSampleValueException; |
| 13 | import de.uka.ipd.sdq.probfunction.math.exception.NegativeDistanceException; |
| 14 | import de.uka.ipd.sdq.probfunction.math.exception.ProbabilityFunctionException; |
| 15 | import de.uka.ipd.sdq.probfunction.math.exception.ProbabilitySumNotOneException; |
| 16 | import de.uka.ipd.sdq.probfunction.math.exception.UnitNameNotSetException; |
| 17 | import de.uka.ipd.sdq.probfunction.math.exception.UnitNotSetException; |
| 18 | import de.uka.ipd.sdq.probfunction.math.exception.UnknownPDFTypeException; |
| 19 | import de.uka.ipd.sdq.probfunction.math.exception.UnorderedDomainException; |
| 20 | |
| 21 | /** |
| 22 | * Supports only the mean value so far. |
| 23 | * |
| 24 | * Some of the other methods could probably be provided. |
| 25 | * |
| 26 | * TODO: A number of calculations are possible, implement them instead of throwing UnsupportedOperationException(). |
| 27 | * |
| 28 | * See e.g. http://en.wikipedia.org/wiki/List_of_convolutions_of_probability_distributions |
| 29 | * @author martens |
| 30 | * |
| 31 | */ |
| 32 | public class ExponentialDistribution extends AbstractContinousPDF implements IExponentialDistribution { |
| 33 | |
| 34 | public ExponentialDistribution(double rate){ |
| 35 | double mean = 1.0/rate; |
| 36 | this.internalFunction = new ExponentialDistributionImpl(mean); |
| 37 | } |
| 38 | |
| 39 | public IProbabilityDensityFunction add(IProbabilityDensityFunction pdf) |
| 40 | throws FunctionsInDifferenDomainsException, |
| 41 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 42 | throw new UnsupportedOperationException(); |
| 43 | } |
| 44 | |
| 45 | public IProbabilityDensityFunction div(IProbabilityDensityFunction pdf) |
| 46 | throws FunctionsInDifferenDomainsException, |
| 47 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 48 | throw new UnsupportedOperationException(); |
| 49 | } |
| 50 | |
| 51 | public IProbabilityDensityFunction getCumulativeFunction() |
| 52 | throws FunctionNotInTimeDomainException { |
| 53 | throw new UnsupportedOperationException(); |
| 54 | } |
| 55 | |
| 56 | public IProbabilityDensityFunction getFourierTransform() |
| 57 | throws FunctionNotInTimeDomainException { |
| 58 | throw new UnsupportedOperationException(); |
| 59 | } |
| 60 | |
| 61 | public IProbabilityDensityFunction getInverseFourierTransform() |
| 62 | throws FunctionNotInFrequencyDomainException { |
| 63 | throw new UnsupportedOperationException(); |
| 64 | } |
| 65 | |
| 66 | public double getLowerDomainBorder() { |
| 67 | throw new UnsupportedOperationException(); |
| 68 | } |
| 69 | |
| 70 | public double greaterThan(IProbabilityDensityFunction pdf) |
| 71 | throws ProbabilityFunctionException { |
| 72 | throw new UnsupportedOperationException(); |
| 73 | } |
| 74 | |
| 75 | public double lessThan(IProbabilityDensityFunction pdf) |
| 76 | throws ProbabilityFunctionException { |
| 77 | throw new UnsupportedOperationException(); |
| 78 | } |
| 79 | |
| 80 | public IProbabilityDensityFunction mult(IProbabilityDensityFunction pdf) |
| 81 | throws FunctionsInDifferenDomainsException, |
| 82 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 83 | throw new UnsupportedOperationException(); |
| 84 | } |
| 85 | |
| 86 | public double probabilisticEquals(IProbabilityDensityFunction pdf) |
| 87 | throws ProbabilityFunctionException { |
| 88 | throw new UnsupportedOperationException(); |
| 89 | } |
| 90 | |
| 91 | public IProbabilityDensityFunction sub(IProbabilityDensityFunction pdf) |
| 92 | throws FunctionsInDifferenDomainsException, |
| 93 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 94 | throw new UnsupportedOperationException(); |
| 95 | } |
| 96 | |
| 97 | public void checkConstrains() throws NegativeDistanceException, |
| 98 | ProbabilitySumNotOneException, FunctionNotInTimeDomainException, |
| 99 | UnitNotSetException, UnitNameNotSetException, |
| 100 | InvalidSampleValueException { |
| 101 | throw new UnsupportedOperationException(); |
| 102 | |
| 103 | } |
| 104 | |
| 105 | public Object getMedian() throws UnorderedDomainException { |
| 106 | throw new UnsupportedOperationException(); |
| 107 | } |
| 108 | |
| 109 | public Object getPercentile(int p) throws IndexOutOfBoundsException, |
| 110 | UnorderedDomainException { |
| 111 | throw new UnsupportedOperationException(); |
| 112 | } |
| 113 | |
| 114 | public boolean hasOrderedDomain() { |
| 115 | throw new UnsupportedOperationException(); |
| 116 | } |
| 117 | |
| 118 | public double getRate() { |
| 119 | return 1.0/((ExponentialDistributionImpl)this.internalFunction).getMean(); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | public IProbabilityDensityFunction scale(double scalar) { |
| 124 | throw new UnsupportedOperationException(); |
| 125 | } |
| 126 | |
| 127 | public IProbabilityDensityFunction shiftDomain(double scalar) |
| 128 | throws DomainNotNumbersException { |
| 129 | throw new UnsupportedOperationException(); |
| 130 | } |
| 131 | |
| 132 | public IProbabilityDensityFunction stretchDomain(double scalar) { |
| 133 | return new ExponentialDistribution(this.getRate() / scalar); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public double getStandardDeviation() { |
| 138 | /** |
| 139 | * Apache math uses the StandardDeviation as mean! |
| 140 | */ |
| 141 | final double m = ((ExponentialDistributionImpl)this.internalFunction).getMean(); |
| 142 | return m; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public double getXinf() { |
| 147 | return 0.0; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public double getXsup() { |
| 152 | return Double.POSITIVE_INFINITY; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | |
| 157 | @Override |
| 158 | public double getArithmeticMeanValue() throws DomainNotNumbersException, |
| 159 | FunctionNotInTimeDomainException { |
| 160 | return ((ExponentialDistributionImpl)this.internalFunction).getMean(); |
| 161 | } |
| 162 | |
| 163 | |
| 164 | } |