Debian Codegraph @

src/dr/inference/distribution/LocationScaleJeffreysPrior.java

raw symbols SCIP
1 /*
2 * LocationScaleJeffreysPrior.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.AbstractModelLikelihood;
29 import dr.inference.model.Model;
30 import dr.inference.model.Parameter;
31 import dr.inference.model.Variable;
32 import org.w3c.dom.Document;
33 import org.w3c.dom.Element;
34
35 /**
36 * @author Marc A. Suchard
37 * @author Robert E. Weiss
38 */
39
40 public class LocationScaleJeffreysPrior extends AbstractModelLikelihood {
41
42
43 public LocationScaleJeffreysPrior(Parameter location, Parameter sigma, Parameter gamma,
44 Parameter alpha0, Parameter beta0, Type type) {
45
46 super("RubioSteele");
47
48 this.location = location;
49 this.sigma = sigma;
50 this.gamma = gamma;
51 this.alpha0 = alpha0;
52 this.beta0 = beta0;
53
54 addVariable(location);
55 addVariable(sigma);
56 addVariable(gamma);
57
58 if (alpha0 != null) addVariable(alpha0);
59 if (beta0 != null) addVariable(beta0);
60
61 this.type = type;
62
63 }
64
65 // **************************************************************
66 // Likelihood IMPLEMENTATION
67 // **************************************************************
68
69 public Model getModel() {
70 return this;
71 }
72
73 /**
74 * Calculate the log likelihood of the current state.
75 *
76 * @return the log likelihood.
77 */
78 public double getLogLikelihood() {
79 double a0 = alpha0 != null ? alpha0.getParameterValue(0) : 0.0;
80 double b0 = beta0 != null ? beta0.getParameterValue(0) : 0.0;
81 return type.logPdf(location.getParameterValue(0), sigma.getParameterValue(0), gamma.getParameterValue(0),
82 a0, b0);
83 }
84
85 public void makeDirty() {
86 }
87
88 public void acceptState() {
89 // DO NOTHING
90 }
91
92 public void restoreState() {
93 // DO NOTHING
94 }
95
96 public void storeState() {
97 // DO NOTHING
98 }
99
100 protected void handleModelChangedEvent(Model model, Object object, int index) {
101 // DO NOTHING
102 }
103
104 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
105 // DO NOTHING
106 }
107
108 // **************************************************************
109 // XMLElement IMPLEMENTATION
110 // **************************************************************
111
112 public Element createElement(Document d) {
113 throw new RuntimeException("Not implemented yet!");
114 }
115
116 private final Parameter location;
117 private final Parameter sigma;
118 private final Parameter gamma;
119 private final Parameter alpha0;
120 private final Parameter beta0;
121
122 private final Type type;
123
124 private interface Compute {
125 double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0);
126 }
127
128 public enum Type implements Compute {
129
130 ISF_AG_BETA("inverseScaleFactorsAGBeta", new Compute() {
131 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
132 return -Math.log(sigma) + (2 * alpha0 - 1) * Math.log(gamma) - (alpha0 + beta0) * Math.log(1.0 + gamma * gamma);
133 }
134 }),
135
136 EPSILON_SKEW_AG_BETA("epsilonSkewAGBeta", new Compute() {
137 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
138 return -Math.log(sigma) + (beta0 - 1) * Math.log(1.0 - gamma) + (alpha0 - 1) * Math.log(1.0 + gamma);
139 }
140 }),
141
142 LOGISTIC_AG_BETA("logisticAGBeta", new Compute() {
143 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
144 return -Math.log(sigma)
145 + alpha0 * Math.log(1.0 + Math.exp(2.0 * gamma))
146 + beta0 * Math.log(1.0 + Math.exp(-2.0 * gamma))
147 - (alpha0 + beta0) * Math.log(1.0 + Math.cosh(2.0 * gamma));
148 }
149 }),
150
151 TWO_SCALE("twoScale", new Compute() {
152 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
153 return -(Math.log(sigma) + Math.log(gamma) + Math.log(sigma + gamma));
154 }
155 }),
156
157 TWO_SCALE_INDEPENDENT("twoScaleIndependent", new Compute() {
158 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
159 throw new RuntimeException("Not yet implemented");
160 }
161 }),
162
163 EPSILON_SKEW("epsilonSkew", new Compute() {
164 @Override
165 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
166 return -2.0 * Math.log(sigma) - Math.log(1.0 - gamma * gamma);
167 }
168 }),
169
170 EPSILON_SKEW_INDEPENDENT("epsilonSkewIndependent", new Compute() {
171 @Override
172 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
173 return -Math.log(sigma) - 0.5 * Math.log(1.0 - gamma * gamma);
174 }
175 }),
176
177 TWO_SCALE2("twoScale", new Compute() {
178 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
179 return -(Math.log(sigma) + Math.log(gamma) + Math.log(sigma + gamma));
180 }
181 });
182
183 Type(String text, Compute compute) {
184 this.text = text;
185 this.compute = compute;
186 }
187
188 private final String text;
189 private final Compute compute;
190
191 public static Type parseFromString(String text) {
192 for (Type scheme : Type.values()) {
193 if (scheme.toString().compareToIgnoreCase(text) == 0)
194 return scheme;
195 }
196 return null;
197 }
198
199 public String toString() {
200 return text;
201 }
202
203 public double logPdf(double mu, double sigma, double gamma, double alpha0, double beta0) {
204 return compute.logPdf(mu, sigma, gamma, alpha0, beta0);
205 }
206 }
207 }
208