| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inference.distribution; |
| 27 |
|
| 28 |
import dr.inference.model.AbstractModel; |
| 29 |
import dr.inference.model.Model; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.inference.model.Variable; |
| 32 |
import dr.inferencexml.distribution.UniformDistributionModelParser; |
| 33 |
import dr.math.UnivariateFunction; |
| 34 |
import dr.math.distributions.UniformDistribution; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public class UniformDistributionModel extends AbstractModel implements ParametricDistributionModel { |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public UniformDistributionModel(Parameter lowerParameter, Parameter upperParameter) { |
| 48 |
|
| 49 |
super(UniformDistributionModelParser.UNIFORM_DISTRIBUTION_MODEL); |
| 50 |
|
| 51 |
this.lowerParameter = lowerParameter; |
| 52 |
addVariable(lowerParameter); |
| 53 |
lowerParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1)); |
| 54 |
this.upperParameter = upperParameter; |
| 55 |
addVariable(upperParameter); |
| 56 |
upperParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1)); |
| 57 |
} |
| 58 |
|
| 59 |
public double getLower() { |
| 60 |
return lowerParameter.getParameterValue(0); |
| 61 |
} |
| 62 |
|
| 63 |
public double getUpper() { |
| 64 |
return upperParameter.getParameterValue(0); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public double pdf(double x) { |
| 72 |
return UniformDistribution.pdf(x, getLower(), getUpper()); |
| 73 |
} |
| 74 |
|
| 75 |
public double logPdf(double x) { |
| 76 |
return UniformDistribution.logPdf(x, getLower(), getUpper()); |
| 77 |
} |
| 78 |
|
| 79 |
public double cdf(double x) { |
| 80 |
return UniformDistribution.cdf(x, getLower(), getUpper()); |
| 81 |
} |
| 82 |
|
| 83 |
public double quantile(double y) { |
| 84 |
return UniformDistribution.quantile(y, getLower(), getUpper()); |
| 85 |
} |
| 86 |
|
| 87 |
public double mean() { |
| 88 |
return UniformDistribution.mean(getLower(), getUpper()); |
| 89 |
} |
| 90 |
|
| 91 |
public double variance() { |
| 92 |
return UniformDistribution.variance(getLower(), getUpper()); |
| 93 |
} |
| 94 |
|
| 95 |
public final UnivariateFunction getProbabilityDensityFunction() { |
| 96 |
return pdfFunction; |
| 97 |
} |
| 98 |
|
| 99 |
private final UnivariateFunction pdfFunction = new UnivariateFunction() { |
| 100 |
public final double evaluate(double x) { |
| 101 |
return 1.0; |
| 102 |
} |
| 103 |
|
| 104 |
public final double getLowerBound() { |
| 105 |
return getLower(); |
| 106 |
} |
| 107 |
|
| 108 |
public final double getUpperBound() { |
| 109 |
return getUpper(); |
| 110 |
} |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
@Override |
| 118 |
public double logPdf(double[] x) { |
| 119 |
return logPdf(x[0]); |
| 120 |
} |
| 121 |
|
| 122 |
@Override |
| 123 |
public Variable<Double> getLocationVariable() { |
| 124 |
throw new UnsupportedOperationException("Not implemented"); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public void handleModelChangedEvent(Model model, Object object, int index) { |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
protected void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
protected void storeState() { |
| 141 |
} |
| 142 |
|
| 143 |
protected void restoreState() { |
| 144 |
} |
| 145 |
|
| 146 |
protected void acceptState() { |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
private final Parameter lowerParameter; |
| 154 |
private final Parameter upperParameter; |
| 155 |
|
| 156 |
} |