Debian Codegraph @

src/dr/evomodel/continuous/BranchMagnitudeAttributeProvider.java

raw symbols SCIP
1 /*
2 * BranchMagnitudeAttributeProvider.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.xml.*;
29
30 /*
31 * @author Marc Suchard
32 */
33 public class BranchMagnitudeAttributeProvider extends BivariateTraitBranchAttributeProvider {
34
35 public static final String MAGNITUDE_PROVIDER = "branchMagnitudes";
36 public static final String SCALE = "scaleByLength";
37 public static String DISTANCE_EXTENSION = ".distance";
38 public static final String RATE_EXTENSION = ".rate";
39
40 public BranchMagnitudeAttributeProvider(AbstractMultivariateTraitLikelihood traitLikelihood, boolean scale) {
41 super(traitLikelihood);
42 this.scale = scale;
43 label = traitName + extensionName();
44 }
45
46 protected String extensionName() {
47 if (scale)
48 return RATE_EXTENSION;
49 return DISTANCE_EXTENSION;
50 }
51
52 protected double convert(double latValue, double longValue, double timeValue) {
53 double result = Math.sqrt(latValue*latValue + longValue*longValue);
54 if (scale)
55 result /= timeValue;
56 return result;
57 }
58
59 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
60
61 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
62
63 AbstractMultivariateTraitLikelihood traitLikelihood = (AbstractMultivariateTraitLikelihood)
64 xo.getChild(SampledMultivariateTraitLikelihood.class);
65
66 boolean scale = xo.getAttribute(SCALE,false);
67
68 return new BranchMagnitudeAttributeProvider(traitLikelihood, scale);
69 }
70
71 public XMLSyntaxRule[] getSyntaxRules() {
72 return new XMLSyntaxRule[] {
73 new ElementRule(AbstractMultivariateTraitLikelihood.class),
74 AttributeRule.newBooleanRule(SCALE,true),
75 };
76 }
77
78 public String getParserDescription() {
79 return null;
80 }
81
82 public Class getReturnType() {
83 return BranchMagnitudeAttributeProvider.class;
84 }
85
86 public String getParserName() {
87 return MAGNITUDE_PROVIDER;
88 }
89 };
90
91 private boolean scale;
92
93 }