Debian Codegraph @

src/dr/evomodelxml/operators/MicrosatelliteUpDownOperatorParser.java

raw symbols SCIP
1 /*
2 * MicrosatUpDownOperatorParser.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.MicrosatelliteUpDownOperator;
29 import dr.inference.model.Parameter;
30 import dr.inference.operators.*;
31 import dr.inferencexml.operators.ScaleOperatorParser;
32 import dr.inferencexml.operators.UpDownOperatorParser;
33 import dr.xml.*;
34
35 /**
36 */
37 public class MicrosatelliteUpDownOperatorParser extends AbstractXMLObjectParser {
38
39 public static final String MICROSAT_UP_DOWN_OPERATOR = "microsatUpDownOperator";
40 public static final String UP = UpDownOperatorParser.UP;
41 public static final String DOWN = UpDownOperatorParser.DOWN;
42
43 public static final String SCALE_FACTOR = ScaleOperatorParser.SCALE_FACTOR;
44
45 public String getParserName() {
46 return MICROSAT_UP_DOWN_OPERATOR;
47 }
48
49 private Scalable.Default[] getArgs(final XMLObject list) throws XMLParseException {
50 Scalable.Default[] args = new Scalable.Default[list.getChildCount()];
51 for (int k = 0; k < list.getChildCount(); ++k) {
52 final Object child = list.getChild(k);
53 if (child instanceof Parameter) {
54 args[k] = new Scalable.Default((Parameter) child);
55 }
56
57 }
58 return args;
59 }
60
61 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
62
63 final double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
64
65 final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
66
67 final AdaptationMode mode = AdaptationMode.parseMode(xo);
68
69 final Scalable.Default[] upArgs = getArgs(xo.getChild(UP));
70 final Scalable.Default[] dnArgs = getArgs(xo.getChild(DOWN));
71
72 return new MicrosatelliteUpDownOperator(upArgs, dnArgs, scaleFactor, weight, mode);
73 }
74
75 public String getParserDescription() {
76 return "This element represents an operator that scales two parameters in different directions. " +
77 "Each operation involves selecting a scale uniformly at random between scaleFactor and 1/scaleFactor. " +
78 "The up parameter is multipled by this scale and the down parameter is divided by this scale.";
79 }
80
81 public Class getReturnType() {
82 return MicrosatelliteUpDownOperator.class;
83 }
84
85 public XMLSyntaxRule[] getSyntaxRules() {
86 return rules;
87 }
88
89 private final XMLSyntaxRule[] ee = {
90 new ElementRule(Parameter.class, true)
91 };
92
93 private final XMLSyntaxRule[] rules = {
94 AttributeRule.newDoubleRule(SCALE_FACTOR),
95 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
96 AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true),
97
98 // Allow an arbitrary number of Parameters or Scalables in up or down
99 new ElementRule(UP, ee, 1, Integer.MAX_VALUE),
100 new ElementRule(DOWN, ee, 1, Integer.MAX_VALUE),
101 };
102 }