Debian Codegraph @

src/dr/inferencexml/operators/InvariantOperatorParser.java

raw symbols SCIP
1 /*
2 * InvariantOperatorParser.java
3 *
4 * Copyright (c) 2002-2017 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.inferencexml.operators;
27
28 import dr.inference.model.Likelihood;
29 import dr.inference.model.Parameter;
30 import dr.inference.operators.InvariantOperator;
31 import dr.inference.operators.MCMCOperator;
32 import dr.xml.*;
33
34 /**
35 *
36 */
37 public class InvariantOperatorParser extends AbstractXMLObjectParser {
38
39 public static final String OPERATOR_NAME = "invariantOperator";
40 private static final String CHECK_LIKELIHOOD = "checkLikelihood";
41 private static final String TRANSLATE = "translate";
42 private static final String ROTATE = "rotate";
43 private static final String DIMENSION = "dimension";
44
45 public String getParserName() {
46 return OPERATOR_NAME;
47 }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
52
53 Parameter parameter = (Parameter) xo.getChild(Parameter.class);
54
55 Likelihood likelihood = (Likelihood) xo.getChild(Likelihood.class);
56
57 boolean translate = xo.getAttribute(TRANSLATE, true);
58 boolean rotate = xo.getAttribute(ROTATE, true);
59 boolean checkLikelihood = xo.getAttribute(CHECK_LIKELIHOOD, true);
60
61 int dim = xo.getIntegerAttribute(DIMENSION);
62
63 return new InvariantOperator.Rotation(parameter, dim, weight, likelihood,
64 translate, rotate, checkLikelihood);
65
66 }
67
68 //************************************************************************
69 // AbstractXMLObjectParser implementation
70 //************************************************************************
71
72 public String getParserDescription() {
73 return "This element returns a operator that forces the entire model likelihood recomputation";
74 }
75
76 public Class getReturnType() {
77 return InvariantOperator.class;
78 }
79
80 public XMLSyntaxRule[] getSyntaxRules() {
81 return rules;
82 }
83
84 private final XMLSyntaxRule[] rules = {
85 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
86 new ElementRule(Parameter.class),
87 AttributeRule.newBooleanRule(TRANSLATE, true),
88 AttributeRule.newBooleanRule(ROTATE, true),
89 AttributeRule.newBooleanRule(CHECK_LIKELIHOOD, true),
90 AttributeRule.newIntegerRule(DIMENSION),
91 new ElementRule(Likelihood.class, true),
92 };
93 }