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