Debian Codegraph @

src/dr/evomodelxml/coalescent/operators/SampleNonActiveGibbsOperatorParser.java

raw symbols SCIP
1 /*
2 * SampleNonActiveGibbsOperatorParser.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.coalescent.operators;
27
28 import dr.evomodel.coalescent.operators.SampleNonActiveGibbsOperator;
29 import dr.inference.distribution.ParametricDistributionModel;
30 import dr.inference.model.Parameter;
31 import dr.inference.operators.MCMCOperator;
32 import dr.xml.*;
33
34 /**
35 */
36 public class SampleNonActiveGibbsOperatorParser extends AbstractXMLObjectParser {
37 public static String SAMPLE_NONACTIVE_GIBBS_OPERATOR = "sampleNonActiveOperator";
38 public static String DISTRIBUTION = "distribution";
39
40 public static String INDICATOR_PARAMETER = "indicators";
41 public static String DATA_PARAMETER = "data";
42
43 public String getParserName() {
44 return SAMPLE_NONACTIVE_GIBBS_OPERATOR;
45 }
46
47 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
48 final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
49
50 XMLObject cxo = xo.getChild(DISTRIBUTION);
51 ParametricDistributionModel distribution =
52 (ParametricDistributionModel) cxo.getChild(ParametricDistributionModel.class);
53
54 cxo = xo.getChild(DATA_PARAMETER);
55 Parameter data = (Parameter) cxo.getChild(Parameter.class);
56
57 cxo = xo.getChild(INDICATOR_PARAMETER);
58 Parameter indicators = (Parameter) cxo.getChild(Parameter.class);
59
60 return new SampleNonActiveGibbsOperator(distribution, data, indicators, weight);
61
62 }
63
64 // ************************************************************************
65 // AbstractXMLObjectParser implementation
66 // ************************************************************************
67
68 public String getParserDescription() {
69 return "This element returns a Gibbs operator for the joint distribution of population sizes.";
70 }
71
72 public Class getReturnType() {
73 return SampleNonActiveGibbsOperator.class;
74 }
75
76 public XMLSyntaxRule[] getSyntaxRules() {
77 return rules;
78 }
79
80 private final XMLSyntaxRule[] rules = {
81 new ElementRule("distribution",
82 new XMLSyntaxRule[]{new ElementRule(ParametricDistributionModel.class)}),
83 new ElementRule(INDICATOR_PARAMETER,
84 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
85 new ElementRule(DATA_PARAMETER,
86 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
87 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
88 };
89
90 }