| 1 | package de.uka.ipd.sdq.probfunction.math.apache.impl; |
| 2 | |
| 3 | import org.apache.commons.math.distribution.ChiSquaredDistributionImpl; |
| 4 | |
| 5 | import de.uka.ipd.sdq.probfunction.math.IChiSquareDistribution; |
| 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 | * Chi-square distribution. The chi-square distribution has a single parameter called the degrees of |
| 23 | * freedoms. |
| 24 | * <p> |
| 25 | * The implementation of this class is partly based on the information given in [1]. |
| 26 | * <p> |
| 27 | * [1] http://en.wikipedia.org/w/index.php?title=Chi-squared_distribution&oldid=461800524 |
| 28 | * |
| 29 | * @author Philipp Merkle |
| 30 | * |
| 31 | */ |
| 32 | public class ChiSquareDistribution extends AbstractContinousPDF implements IChiSquareDistribution { |
| 33 | |
| 34 | private int degreesOfFreedom; |
| 35 | |
| 36 | /** |
| 37 | * Default constructor. |
| 38 | * |
| 39 | * @param degreesOfFreedom |
| 40 | * the parameter of this distribution, which must be a positive integer |
| 41 | */ |
| 42 | public ChiSquareDistribution(int degreesOfFreedom) { |
| 43 | assert (degreesOfFreedom > 0) : "The parameter degrees of freedom must be a positive integer."; |
| 44 | this.degreesOfFreedom = degreesOfFreedom; |
| 45 | this.internalFunction = new ChiSquaredDistributionImpl(degreesOfFreedom); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public double getDegreesOfFreedom() { |
| 50 | return this.degreesOfFreedom; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public double getVariance() { |
| 55 | // this method has been implemented in accordance with [1] |
| 56 | return 2.0 * this.degreesOfFreedom; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public double getStandardDeviation() { |
| 61 | return Math.sqrt(this.getVariance()); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public double getXinf() { |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public double getXsup() { |
| 71 | return Double.POSITIVE_INFINITY; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public IProbabilityDensityFunction add(IProbabilityDensityFunction pdf) throws FunctionsInDifferenDomainsException, |
| 76 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 77 | throw new UnsupportedOperationException(); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public IProbabilityDensityFunction div(IProbabilityDensityFunction pdf) throws FunctionsInDifferenDomainsException, |
| 82 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 83 | throw new UnsupportedOperationException(); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public IProbabilityDensityFunction getCumulativeFunction() throws FunctionNotInTimeDomainException { |
| 88 | throw new UnsupportedOperationException(); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public IProbabilityDensityFunction getFourierTransform() throws FunctionNotInTimeDomainException { |
| 93 | throw new UnsupportedOperationException(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public IProbabilityDensityFunction getInverseFourierTransform() throws FunctionNotInFrequencyDomainException { |
| 98 | throw new UnsupportedOperationException(); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public double getLowerDomainBorder() { |
| 103 | throw new UnsupportedOperationException(); |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public double greaterThan(IProbabilityDensityFunction pdf) throws ProbabilityFunctionException { |
| 108 | throw new UnsupportedOperationException(); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public double lessThan(IProbabilityDensityFunction pdf) throws ProbabilityFunctionException { |
| 113 | throw new UnsupportedOperationException(); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public IProbabilityDensityFunction mult(IProbabilityDensityFunction pdf) |
| 118 | throws FunctionsInDifferenDomainsException, UnknownPDFTypeException, IncompatibleUnitsException { |
| 119 | throw new UnsupportedOperationException(); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public double probabilisticEquals(IProbabilityDensityFunction pdf) throws ProbabilityFunctionException { |
| 124 | throw new UnsupportedOperationException(); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public IProbabilityDensityFunction scale(double scalar) { |
| 129 | throw new UnsupportedOperationException(); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public IProbabilityDensityFunction shiftDomain(double scalar) throws DomainNotNumbersException { |
| 134 | throw new UnsupportedOperationException(); |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public IProbabilityDensityFunction stretchDomain(double scalar) { |
| 139 | throw new UnsupportedOperationException(); |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public IProbabilityDensityFunction sub(IProbabilityDensityFunction pdf) throws FunctionsInDifferenDomainsException, |
| 144 | UnknownPDFTypeException, IncompatibleUnitsException { |
| 145 | throw new UnsupportedOperationException(); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void checkConstrains() throws NegativeDistanceException, ProbabilitySumNotOneException, |
| 150 | FunctionNotInTimeDomainException, UnitNotSetException, UnitNameNotSetException, InvalidSampleValueException { |
| 151 | throw new UnsupportedOperationException(); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public double getArithmeticMeanValue() throws DomainNotNumbersException, FunctionNotInTimeDomainException { |
| 156 | // this method has been implemented in accordance with [1] |
| 157 | return this.getDegreesOfFreedom(); |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public Object getMedian() throws UnorderedDomainException { |
| 162 | // this method has been implemented in accordance with [1] |
| 163 | double intermediateResult = 1 - (2.0 / (9.0 * degreesOfFreedom)); |
| 164 | return degreesOfFreedom * Math.pow(intermediateResult, 3); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public Object getPercentile(int p) throws IndexOutOfBoundsException, UnorderedDomainException { |
| 169 | throw new UnsupportedOperationException(); |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public boolean hasOrderedDomain() { |
| 174 | throw new UnsupportedOperationException(); |
| 175 | } |
| 176 | |
| 177 | } |