Debian Codegraph @

src/dr/evomodelxml/operators/SubtreeLeapOperatorParser.java

raw symbols SCIP
1 /*
2 * SubtreeLeapOperatorParser.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.evomodelxml.operators;
27
28 import dr.evomodel.operators.SubtreeLeapOperator;
29 import dr.evomodel.tree.TreeModel;
30 import dr.inference.operators.AdaptableMCMCOperator;
31 import dr.inference.operators.AdaptationMode;
32 import dr.inference.operators.MCMCOperator;
33 import dr.xml.*;
34
35 /**
36 */
37 public class SubtreeLeapOperatorParser extends AbstractXMLObjectParser {
38
39 public static final String SUBTREE_LEAP = "subtreeLeap";
40
41 public static final String SIZE = "size";
42 public static final String TARGET_ACCEPTANCE = "targetAcceptance";
43
44 public String getParserName() {
45 return SUBTREE_LEAP;
46 }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50 AdaptationMode mode = AdaptationMode.parseMode(xo);
51
52 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
53 final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
54
55 // size attribute is mandatory
56 final double size = xo.getAttribute(SIZE, Double.NaN);
57 final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
58
59 if (size <= 0.0) {
60 throw new XMLParseException("The SubTreeLeap size attribute must be positive and non-zero.");
61 }
62
63 if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) {
64 throw new XMLParseException("Target acceptance probability has to lie in (0, 1)");
65 }
66 SubtreeLeapOperator operator = new SubtreeLeapOperator(treeModel, weight, size, targetAcceptance, mode);
67
68 return operator;
69 }
70
71 public String getParserDescription() {
72 return "An operator that moves a subtree a certain patristic distance.";
73 }
74
75 public Class getReturnType() {
76 return SubtreeLeapOperator.class;
77 }
78
79 public XMLSyntaxRule[] getSyntaxRules() {
80 return rules;
81 }
82
83 private final XMLSyntaxRule[] rules = {
84 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
85 AttributeRule.newDoubleRule(SIZE, false),
86 AttributeRule.newDoubleRule(TARGET_ACCEPTANCE, true),
87 AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true),
88 new ElementRule(TreeModel.class)
89 };
90
91 }