Debian Codegraph @

src/dr/inferencexml/operators/TeamOperatorParser.java

raw symbols SCIP
1 /*
2 * TeamOperatorParser.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.operators.MCMCOperator;
29 import dr.inference.operators.TeamOperator;
30 import dr.xml.*;
31
32 /**
33 *
34 */
35 public class TeamOperatorParser extends AbstractXMLObjectParser {
36
37 public static final String TEAM_OPERATOR = "teamOperator";
38 public static final String SUBSET_SIZE = "size";
39 // public static final String TARGET_ACCEPTANCE = "targetAcceptance";
40
41 public String getParserName() {
42 return TEAM_OPERATOR;
43 }
44
45 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
46
47 final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
48 final int size = xo.getIntegerAttribute(SUBSET_SIZE);
49 //final double targetProb = xo.getAttribute(TARGET_ACCEPTANCE, 0.2);
50
51 // if (targetProb <= 0.0 || targetProb >= 1.0)
52 // throw new RuntimeException("Target acceptance probability must be between 0.0 and 1.0");
53
54 MCMCOperator[] o = new MCMCOperator[xo.getChildCount()];
55 for (int i = 0; i < o.length; i++) {
56 o[i] = (MCMCOperator) xo.getChild(i);
57 }
58
59 return new TeamOperator(o, size, weight);
60 }
61
62 //************************************************************************
63 // AbstractXMLObjectParser implementation
64 //************************************************************************
65
66 public String getParserDescription() {
67 return "An arbitrary list of operators; A random subset of size N is aggregated in one operation." +
68 " Operators may have unequal weights - in that case a subset probability of selection is proportional to " +
69 "the sum of it's members weights.";
70 }
71
72 public Class getReturnType() {
73 return TeamOperator.class;
74 }
75
76 public XMLSyntaxRule[] getSyntaxRules() {
77 return rules;
78 }
79
80 private final XMLSyntaxRule[] rules = {
81 new ElementRule(MCMCOperator.class, 1, Integer.MAX_VALUE),
82 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
83 AttributeRule.newIntegerRule(SUBSET_SIZE)
84 //AttributeRule.newDoubleRule(TARGET_ACCEPTANCE, true)
85 };
86 }