Debian Codegraph @

src/dr/inferencexml/operators/HierarchicalBitFlipOperatorParser.java

raw symbols SCIP
1 /*
2 * HierarchicalBitFlipOperatorParser.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.inferencexml.operators;
27
28 import dr.inference.model.Parameter;
29 import dr.inference.operators.HierarchicalBitFlipOperator;
30 import dr.inference.operators.MCMCOperator;
31 import dr.xml.*;
32
33 /**
34 * @author Gabriela Cybis
35 */
36
37
38 public class HierarchicalBitFlipOperatorParser extends AbstractXMLObjectParser {
39
40 public static final String HIERARCHICAL_BIT_FLIP_OPERATOR = "HierarchicalBitFlipOperator";
41 public static final String USES_SUM_PRIOR = "usesPriorOnSum";
42 public static final String H_PARAMETER = "hParameter";
43 public static final String STRATA_PARAMETERS = "strataParameters";
44
45
46
47 public String getParserName() {
48 return HIERARCHICAL_BIT_FLIP_OPERATOR;
49 }
50
51 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
52
53 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
54 boolean usesPriorOnSum = xo.getAttribute(USES_SUM_PRIOR,false);
55
56 XMLObject cxo = xo.getChild(H_PARAMETER);
57 Parameter hParameter = (Parameter) cxo.getChild(Parameter.class);
58
59 cxo = xo.getChild(STRATA_PARAMETERS);
60 int NStrata = cxo.getChildCount();
61
62 Parameter[] strataParameters = new Parameter[NStrata];
63 for (int i = 0; i < NStrata; i++) {
64 Parameter parameter = (Parameter) cxo.getChild(i);
65 strataParameters[i] = parameter;
66 }
67
68
69 return new HierarchicalBitFlipOperator(hParameter, strataParameters,NStrata, weight, usesPriorOnSum);
70 }
71
72 //************************************************************************
73 // AbstractXMLObjectParser implementation
74 //************************************************************************
75
76 public String getParserDescription() {
77 return "This element returns a bit-flip operator on a set of hierarchical and strata parameters simulatneously.";
78 }
79
80 public Class getReturnType() {
81 return HierarchicalBitFlipOperator.class;
82 }
83
84 public XMLSyntaxRule[] getSyntaxRules() {
85 return rules;
86 }
87
88 private final XMLSyntaxRule[] rules = {
89 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
90 AttributeRule.newBooleanRule(USES_SUM_PRIOR,true),
91 new ElementRule(H_PARAMETER,
92 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
93 new ElementRule(STRATA_PARAMETERS,
94 new XMLSyntaxRule[]{new ElementRule(Parameter.class, 1, Integer.MAX_VALUE)}),
95 };
96
97 }
98
99
100
101
102