Debian Codegraph @

src/dr/inference/distribution/TDistributionModel.java

raw symbols SCIP
1 /*
2 * TDistributionModel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Marc A. Suchard
41 * @author Robert E. Weiss
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 // Interface Distribution
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 // Interface DensityModel
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 // Interface Model
137 // *****************************************************************
138
139 public void handleModelChangedEvent(Model model, Object object, int index) {
140 // no intermediates need to be recalculated...
141 }
142
143 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
144 // no intermediates need to be recalculated...
145 }
146
147 protected void storeState() {
148 } // no additional state needs storing
149
150 protected void restoreState() {
151 } // no additional state needs restoring
152
153 protected void acceptState() {
154 } // no additional state needs accepting
155
156 public Element createElement(Document document) {
157 throw new RuntimeException("Not implemented!");
158 }
159
160 // **************************************************************
161 // Private instance variables
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 }