| 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.NormalDistributionModelParser; |
| 33 |
import dr.math.UnivariateFunction; |
| 34 |
import dr.math.distributions.RandomGenerator; |
| 35 |
import dr.math.distributions.TDistribution; |
| 36 |
import org.w3c.dom.Document; |
| 37 |
import org.w3c.dom.Element; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class TDistributionModel extends AbstractModel implements ParametricDistributionModel, RandomGenerator { |
| 45 |
|
| 46 |
|
| 47 |
public TDistributionModel(Parameter location, Parameter scale, Parameter df) { |
| 48 |
super(NormalDistributionModelParser.NORMAL_DISTRIBUTION_MODEL); |
| 49 |
|
| 50 |
this.location = location; |
| 51 |
addVariable(location); |
| 52 |
location.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1)); |
| 53 |
|
| 54 |
this.scale = scale; |
| 55 |
addVariable(scale); |
| 56 |
scale.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 57 |
|
| 58 |
this.df = df; |
| 59 |
addVariable(df); |
| 60 |
df.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); |
| 61 |
} |
| 62 |
|
| 63 |
public double getLocation() { |
| 64 |
return location.getValue(0); |
| 65 |
} |
| 66 |
|
| 67 |
public double getScale() { |
| 68 |
return scale.getValue(0); |
| 69 |
} |
| 70 |
|
| 71 |
public double getDF() { |
| 72 |
return df.getValue(0); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public double pdf(double x) { |
| 80 |
throw new RuntimeException("Not yet implemented."); |
| 81 |
} |
| 82 |
|
| 83 |
public double logPdf(double x) { |
| 84 |
return TDistribution.logPDF(x, getLocation(), getScale(), getDF()); |
| 85 |
} |
| 86 |
|
| 87 |
public double cdf(double x) { |
| 88 |
throw new RuntimeException("Not yet implemented."); |
| 89 |
} |
| 90 |
|
| 91 |
public double quantile(double y) { |
| 92 |
throw new RuntimeException("Not yet implemented."); |
| 93 |
} |
| 94 |
|
| 95 |
public double mean() { |
| 96 |
throw new RuntimeException("Not yet implemented."); |
| 97 |
} |
| 98 |
|
| 99 |
public double variance() { |
| 100 |
throw new RuntimeException("Not yet implemented."); |
| 101 |
} |
| 102 |
|
| 103 |
public final UnivariateFunction getProbabilityDensityFunction() { |
| 104 |
return pdfFunction; |
| 105 |
} |
| 106 |
|
| 107 |
private final UnivariateFunction pdfFunction = new UnivariateFunction() { |
| 108 |
public final double evaluate(double x) { |
| 109 |
return pdf(x); |
| 110 |
} |
| 111 |
|
| 112 |
public final double getLowerBound() { |
| 113 |
return Double.NEGATIVE_INFINITY; |
| 114 |
} |
| 115 |
|
| 116 |
public final double getUpperBound() { |
| 117 |
return Double.POSITIVE_INFINITY; |
| 118 |
} |
| 119 |
}; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
@Override |
| 126 |
public double logPdf(double[] x) { |
| 127 |
return logPdf(x[0]); |
| 128 |
} |
| 129 |
|
| 130 |
@Override |
| 131 |
public Variable<Double> getLocationVariable() { |
| 132 |
return location; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public void handleModelChangedEvent(Model model, Object object, int index) { |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
protected void storeState() { |
| 148 |
} |
| 149 |
|
| 150 |
protected void restoreState() { |
| 151 |
} |
| 152 |
|
| 153 |
protected void acceptState() { |
| 154 |
} |
| 155 |
|
| 156 |
public Element createElement(Document document) { |
| 157 |
throw new RuntimeException("Not implemented!"); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
private final Variable<Double> location; |
| 165 |
private final Variable<Double> scale; |
| 166 |
private final Variable<Double> df; |
| 167 |
|
| 168 |
public Object nextRandom() { |
| 169 |
throw new RuntimeException("Not yet implemented."); |
| 170 |
} |
| 171 |
|
| 172 |
public double logPdf(Object x) { |
| 173 |
double v = (Double) x; |
| 174 |
return logPdf(v); |
| 175 |
} |
| 176 |
} |