Debian Codegraph @

src/dr/inference/distribution/PoissonDistributionModel.java

raw symbols SCIP
1 /*
2 * PoissonDistributionModel.java
3 *
4 * Copyright (c) 2002-2016 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.*;
29 import dr.inferencexml.distribution.PoissonDistributionModelParser;
30 import dr.math.UnivariateFunction;
31 import dr.math.distributions.PoissonDistribution;
32 import org.w3c.dom.Document;
33 import org.w3c.dom.Element;
34
35 /**
36 * A class that acts as a model for Poisson distributed data.
37 *
38 * @author Andrew Rambaut
39 * @version $Id$
40 */
41
42 public class PoissonDistributionModel extends AbstractModel implements ParametricDistributionModel {
43
44 /**
45 * Constructor.
46 */
47 public PoissonDistributionModel(Variable<Double> mean) {
48
49 super(PoissonDistributionModelParser.POISSON_DISTRIBUTION_MODEL);
50
51 this.mean = mean;
52 addVariable(mean);
53 mean.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
54 }
55
56 // *****************************************************************
57 // Interface Distribution
58 // *****************************************************************
59
60 public double pdf(double x) {
61 return PoissonDistribution.pdf(x, mean());
62 }
63
64 public double logPdf(double x) { return PoissonDistribution.logPdf(x, mean()); }
65
66 public double cdf(double x) {
67 return PoissonDistribution.cdf(x, mean());
68 }
69
70 public double quantile(double y) {
71 return PoissonDistribution.quantile(y, mean());
72 }
73
74 public double mean() {
75 return mean.getValue(0);
76 }
77
78 public double variance() {
79 throw new RuntimeException("Not implemented!");
80 }
81
82 public final UnivariateFunction getProbabilityDensityFunction() {
83 return pdfFunction;
84 }
85
86 private final UnivariateFunction pdfFunction = new UnivariateFunction() {
87 public final double evaluate(double x) {
88 return pdf(x);
89 }
90
91 public final double getLowerBound() {
92 return 0.0;
93 }
94
95 public final double getUpperBound() {
96 return Double.POSITIVE_INFINITY;
97 }
98 };
99
100 // *****************************************************************
101 // Interface DensityModel
102 // *****************************************************************
103
104 @Override
105 public double logPdf(double[] x) {
106 return logPdf(x[0]);
107 }
108
109 @Override
110 public Variable<Double> getLocationVariable() {
111 return mean;
112 }
113
114 // *****************************************************************
115 // Interface Model
116 // *****************************************************************
117
118 public void handleModelChangedEvent(Model model, Object object, int index) {
119 // no intermediates need to be recalculated...
120 }
121
122 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
123 // using a depricated method or else we would be reallocating this every call...
124 }
125
126 protected void storeState() {
127 } // no additional state needs storing
128
129 protected void restoreState() {
130 } // no additional state needs restoring
131
132 protected void acceptState() {
133 } // no additional state needs accepting
134
135 public Element createElement(Document document) {
136 throw new RuntimeException("Not implemented!");
137 }
138
139 // **************************************************************
140 // Private instance variables
141 // **************************************************************
142
143 private final Variable<Double> mean;
144
145 }