Debian Codegraph @

src/dr/evomodelxml/operators/RandomWalkIntegerSetSizeWeightedOperatorParser.java

raw symbols SCIP
1 /*
2 * RandomWalkIntegerSetSizeWeightedOperatorParser.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.xml.*;
29 import dr.inference.operators.MCMCOperator;
30 import dr.evomodel.operators.RandomWalkIntegerSetSizeWeightedOperator;
31 import dr.inference.model.Parameter;
32 import dr.evomodel.tree.MicrosatelliteSamplerTreeModel;
33
34 /**
35 * @author Chieh-Hsi Wu
36 *
37 * This is the parser for the random walk integer set size weighted operator.
38 */
39 public class RandomWalkIntegerSetSizeWeightedOperatorParser extends AbstractXMLObjectParser {
40
41 public static final String RANDOM_WALK_INT_SET_SIZE_WGT_OP = "randomWalkIntegerSetSizeWeightedOperator";
42
43 public static final String WINDOW_SIZE = "windowSize";
44 public static final String BASE_SET_SIZE = "baseSetSize";
45
46 public String getParserName() {
47 return RANDOM_WALK_INT_SET_SIZE_WGT_OP;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
53
54 double d = xo.getDoubleAttribute(WINDOW_SIZE);
55 if (d != Math.floor(d)) {
56 throw new XMLParseException("The window size of a " + RANDOM_WALK_INT_SET_SIZE_WGT_OP + " should be an integer");
57 }
58
59 double baseSetSize = xo.getDoubleAttribute(BASE_SET_SIZE);
60
61 int windowSize = (int)d;
62 Parameter parameter = (Parameter) xo.getChild(Parameter.class);
63 MicrosatelliteSamplerTreeModel msatSampleTreeModel = (MicrosatelliteSamplerTreeModel)xo.getChild(MicrosatelliteSamplerTreeModel.class);
64
65 return new RandomWalkIntegerSetSizeWeightedOperator(parameter, windowSize, weight, msatSampleTreeModel, baseSetSize);
66 }
67
68 public String getParserDescription() {
69 return "This element returns a random walk set size weighted operator on a given parameter.";
70 }
71
72 public Class getReturnType() {
73 return RandomWalkIntegerSetSizeWeightedOperator.class;
74 }
75
76 public XMLSyntaxRule[] getSyntaxRules() {
77 return rules;
78 }
79
80 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
81 AttributeRule.newDoubleRule(WINDOW_SIZE),
82 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
83 AttributeRule.newDoubleRule(BASE_SET_SIZE),
84 new ElementRule(Parameter.class),
85 new ElementRule(MicrosatelliteSamplerTreeModel.class)
86 };
87 }