Debian Codegraph @

src/dr/inference/distribution/UniformDistributionModel.java

raw symbols SCIP
1 /*
2 * UniformDistributionModel.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.UniformDistributionModelParser;
33 import dr.math.UnivariateFunction;
34 import dr.math.distributions.UniformDistribution;
35
36 /**
37 * A class that acts as a model for uniformly distributed data.
38 *
39 * @author Alexei Drummond
40 * $Id$
41 */
42
43 public class UniformDistributionModel extends AbstractModel implements ParametricDistributionModel {
44 /*
45 * Constructor.
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 // Interface Distribution
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 // Interface DensityModel
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 // Interface Model
130 // *****************************************************************
131
132 public void handleModelChangedEvent(Model model, Object object, int index) {
133 // no intermediates need to be recalculated...
134 }
135
136 protected void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
137 // no intermediates need to be recalculated...
138 }
139
140 protected void storeState() {
141 } // no additional state needs storing
142
143 protected void restoreState() {
144 } // no additional state needs restoring
145
146 protected void acceptState() {
147 } // no additional state needs accepting
148
149 // **************************************************************
150 // Private instance variables
151 // **************************************************************
152
153 private final Parameter lowerParameter;
154 private final Parameter upperParameter;
155
156 }