Debian Codegraph @

src/dr/evomodel/continuous/GreatCircleDiffusionModel.java

raw symbols SCIP
1 /*
2 * GreatCircleDiffusionModel.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.evomodel.continuous;
27
28 import dr.geo.math.SphericalPolarCoordinates;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 /**
33 * @author Marc A. Suchard
34 */
35
36 public class GreatCircleDiffusionModel extends MultivariateDiffusionModel {
37
38 public static final String DIFFUSION_PROCESS = "greatCircleDiffusionModel";
39 public static final String DIFFUSION_CONSTANT = "precision";
40 public static final String COEFFICIENT = "diffusionCoefficient";
41 // public static final String BIAS = "mu";
42 // public static final String PRECISION_TREE_ATTRIBUTE = "precision";
43
44 public GreatCircleDiffusionModel(Parameter precision, Parameter coefficient) {
45 super();
46 this.precision = precision;
47 addVariable(precision);
48 this.coefficient = coefficient;
49 if (coefficient != null)
50 addVariable(coefficient);
51 }
52
53 public GreatCircleDiffusionModel(Parameter precision) {
54 this(precision, null);
55 }
56
57 protected double calculateLogDensity(double[] start, double[] stop, double time) {
58
59 SphericalPolarCoordinates coord1 = new SphericalPolarCoordinates(start[0], start[1]);
60 SphericalPolarCoordinates coord2 = new SphericalPolarCoordinates(stop[0], stop[1]);
61
62 double distance = coord1.distance(coord2);
63
64 double inverseVariance = precision.getParameterValue(0) / time;
65 // TODO Check!
66 // I believe this is a 2D (not 1D) Normal diffusion approx; hence the precision is squared (compared to 1D)
67 // in the normalization constant
68 if (coefficient == null)
69 return -LOG2PI + Math.log(inverseVariance) - 0.5 * (distance * distance * inverseVariance);
70 double coef = -coefficient.getParameterValue(0);
71 return -LOG2PI + coef * Math.log(inverseVariance) - 0.5 * (distance * distance * Math.pow(inverseVariance, coef));
72 }
73
74 protected void calculatePrecisionInfo() {
75 }
76
77
78 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
79
80 public String getParserName() {
81 return DIFFUSION_PROCESS;
82 }
83
84 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
85
86 Parameter diffusionParam = (Parameter) xo.getChild(Parameter.class);
87 Parameter coefficient = null;
88 if (xo.hasChildNamed(COEFFICIENT))
89 coefficient = (Parameter) xo.getChild(COEFFICIENT).getChild(Parameter.class);
90
91 return new GreatCircleDiffusionModel(diffusionParam, coefficient);
92 }
93
94 //************************************************************************
95 // AbstractXMLObjectParser implementation
96 //************************************************************************
97
98 public String getParserDescription() {
99 return "Describes a bivariate diffusion process using great circle distances.";
100 }
101
102 public XMLSyntaxRule[] getSyntaxRules() {
103 return rules;
104 }
105
106 private final XMLSyntaxRule[] rules = {
107 new ElementRule(Parameter.class),
108 new ElementRule(COEFFICIENT,
109 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true),
110 };
111
112 public Class getReturnType() {
113 return MultivariateDiffusionModel.class;
114 }
115 };
116
117 private Parameter precision;
118 private Parameter coefficient;
119
120 }