Debian Codegraph @

src/dr/inference/distribution/SkewNormalDistributionModel.java

raw symbols SCIP
1 /*
2 * SkewNormalDistributionModel.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.math.UnivariateFunction;
33 import dr.math.distributions.NormalDistribution;
34 import org.w3c.dom.Document;
35 import org.w3c.dom.Element;
36
37 /**
38 * A class that acts as a model for skew-normally distributed data.
39 *
40 * @author Marc A. Suchard
41 */
42
43 public class SkewNormalDistributionModel extends AbstractModel implements ParametricDistributionModel {
44
45 public static final String SKEW_NORMAL_DISTRIBUTION_MODEL = "skewNormalDistributionModel";
46
47 /**
48 * Constructor.
49 */
50 public SkewNormalDistributionModel(Variable<Double> location, Variable<Double> scale, Variable<Double> shape) {
51
52 super(SKEW_NORMAL_DISTRIBUTION_MODEL);
53
54 this.location = location;
55 this.scale = scale;
56 this.shape = shape;
57
58 addVariable(location);
59 location.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1));
60 addVariable(scale);
61 scale.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
62 addVariable(shape);
63 shape.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1));
64
65 }
66
67 private double shift(double x) {
68 return (x - location.getValue(0)) / scale.getValue(0);
69 }
70
71
72 // *****************************************************************
73 // Interface Distribution
74 // *****************************************************************
75
76 public double pdf(double x) {
77 double delta = shift(x);
78 return 2.0 / scale.getValue(0) * NormalDistribution.pdf(delta, 0, 1) * NormalDistribution.cdf(shape.getValue(0) * delta, 0, 1);
79 }
80
81 public double logPdf(double x) {
82 return Math.log(pdf(x));
83 }
84
85 public double cdf(double x) {
86 throw new IllegalArgumentException("Not yet implement");
87 // return NormalDistribution.cdf(x, mean(), getStdev());
88 }
89
90 public double quantile(double y) {
91 throw new IllegalArgumentException("Not yet implement");
92 }
93
94 public double mean() {
95 throw new IllegalArgumentException("Not yet implement");
96 }
97
98 public double variance() {
99 throw new IllegalArgumentException("Not yet implement");
100 }
101
102 public final UnivariateFunction getProbabilityDensityFunction() {
103 return pdfFunction;
104 }
105
106 private final UnivariateFunction pdfFunction = new UnivariateFunction() {
107 public final double evaluate(double x) {
108 return pdf(x);
109 }
110
111 public final double getLowerBound() {
112 return Double.NEGATIVE_INFINITY;
113 }
114
115 public final double getUpperBound() {
116 return Double.POSITIVE_INFINITY;
117 }
118 };
119
120 // *****************************************************************
121 // Interface Model
122 // *****************************************************************
123
124 public void handleModelChangedEvent(Model model, Object object, int index) {
125 // no intermediates need to be recalculated...
126 }
127
128 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
129 // no intermediates need to be recalculated...
130 }
131
132 protected void storeState() {
133 } // no additional state needs storing
134
135 protected void restoreState() {
136 } // no additional state needs restoring
137
138 protected void acceptState() {
139 } // no additional state needs accepting
140
141 public Element createElement(Document document) {
142 throw new RuntimeException("Not implemented!");
143 }
144
145 // *****************************************************************
146 // Interface DensityModel
147 // *****************************************************************
148
149 @Override
150 public double logPdf(double[] x) {
151 return logPdf(x[0]);
152 }
153
154 @Override
155 public Variable<Double> getLocationVariable() {
156 return location;
157 }
158
159 // **************************************************************
160 // Private instance variables
161 // **************************************************************
162
163 private final Variable<Double> location;
164 private final Variable<Double> scale;
165 private final Variable<Double> shape;
166 }