Debian Codegraph @

src/dr/evomodelxml/operators/SubtreeJumpOperatorParser.java

raw symbols SCIP
1 /*
2 * SubtreeJumpOperatorParser.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.FixedHeightSubtreePruneRegraftOperator;
29 import dr.evomodel.operators.SubtreeJumpOperator;
30 import dr.evomodel.tree.TreeModel;
31 import dr.inference.operators.AdaptableMCMCOperator;
32 import dr.inference.operators.AdaptationMode;
33 import dr.inference.operators.MCMCOperator;
34 import dr.xml.*;
35
36 /**
37 */
38 public class SubtreeJumpOperatorParser extends AbstractXMLObjectParser {
39
40 public static final String SUBTREE_JUMP = "subtreeJump";
41
42 public static final String SIZE = "size";
43 public static final String TARGET_ACCEPTANCE = "targetAcceptance";
44 public static final String UNIFORM = "uniform";
45
46
47 public String getParserName() {
48 return SUBTREE_JUMP;
49 }
50
51 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
52
53 AdaptationMode mode = AdaptationMode.parseMode(xo);
54
55 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
56 final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
57
58 // size attribute is mandatory
59 final double size = xo.getAttribute(SIZE, Double.NaN);
60 final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
61 final boolean uniform = xo.getAttribute(UNIFORM, false);
62
63 if (size <= 0.0) {
64 throw new XMLParseException("The SubTreeLeap size attribute must be positive and non-zero.");
65 }
66
67 if (Double.isInfinite(size)) {
68 // uniform so no auto optimize
69 mode = AdaptationMode.ADAPTATION_OFF;
70 }
71
72 if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) {
73 throw new XMLParseException("Target acceptance probability has to lie in (0, 1)");
74 }
75
76 SubtreeJumpOperator operator = new SubtreeJumpOperator(treeModel, weight, size, targetAcceptance, uniform, mode);
77 // operator.setTargetAcceptanceProbability(targetAcceptance);
78
79 return operator;
80 }
81
82 public String getParserDescription() {
83 return "An operator that jumps a subtree to another edge at the same height.";
84 }
85
86 public Class getReturnType() {
87 return FixedHeightSubtreePruneRegraftOperator.class;
88 }
89
90 public XMLSyntaxRule[] getSyntaxRules() {
91 return rules;
92 }
93
94 private final XMLSyntaxRule[] rules = {
95 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
96 AttributeRule.newDoubleRule(SIZE, true),
97 AttributeRule.newDoubleRule(TARGET_ACCEPTANCE, true),
98 AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true),
99 new ElementRule(TreeModel.class)
100 };
101
102 }