Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * BayesianSkylineGibbsOperatorParser.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.BayesianSkylineLikelihood;
29 import dr.evomodel.coalescent.operators.BayesianSkylineGibbsOperator;
30 import dr.inference.model.Parameter;
31 import dr.inference.operators.MCMCOperator;
32 import dr.xml.*;
33
34 /**
35 */
36 public class BayesianSkylineGibbsOperatorParser extends AbstractXMLObjectParser {
37 public static final String BAYESIAN_SKYLINE_GIBBS_OPERATOR = "generalizedSkylineGibbsOperator";
38 public static final String POPULATION_SIZES = "populationSizes";
39 public static final String GROUP_SIZES = "groupSizes";
40 public static final String LOWER = "lower";
41 public static final String UPPER = "upper";
42
43 public static final String JEFFREYS = "Jeffreys";
44 public static final String EXPONENTIALMARKOV = "exponentialMarkov";
45 public static final String SHAPE = "shape";
46 public static final String REVERSE = "reverse";
47 public static final String ITERATIONS = "iterations";
48 public static final String TYPE = "type";
49
50 public static final String STEPWISE = "stepwise";
51 public static final String LINEAR = "linear";
52 public static final String EXPONENTIAL = "exponential";
53
54 public String getParserName() {
55 return BAYESIAN_SKYLINE_GIBBS_OPERATOR;
56 }
57
58 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
59
60 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
61
62 final double lowerBound = xo.getAttribute(LOWER, 0.0);
63 final double upperBound = xo.getAttribute(UPPER, Double.MAX_VALUE);
64 final boolean jeffreysPrior = xo.getAttribute(JEFFREYS, true);
65
66 boolean exponentialMarkovPrior = xo.getAttribute(EXPONENTIALMARKOV, false);
67 double shape = xo.getAttribute(SHAPE, 1.0);
68 boolean reverse = xo.getAttribute(REVERSE, false);
69 int iterations = xo.getAttribute(ITERATIONS, 1);
70
71 BayesianSkylineLikelihood bayesianSkylineLikelihood = (BayesianSkylineLikelihood) xo
72 .getChild(BayesianSkylineLikelihood.class);
73
74 // This is the parameter on which this operator acts
75 Parameter paramPops = (Parameter) xo.getChild(Parameter.class);
76
77 Parameter paramGroups = bayesianSkylineLikelihood.getGroupSizeParameter();
78
79 final int type = bayesianSkylineLikelihood.getType();
80
81 if (type != BayesianSkylineLikelihood.STEPWISE_TYPE) {
82 throw new XMLParseException(
83 "Need stepwise control points (set 'linear=\"false\"' in skyline Gibbs operator)");
84 }
85
86 return new BayesianSkylineGibbsOperator(bayesianSkylineLikelihood,
87 paramPops, paramGroups, type, weight, lowerBound,
88 upperBound, jeffreysPrior, exponentialMarkovPrior,
89 shape, reverse, iterations);
90
91 }
92
93 // ************************************************************************
94 // AbstractXMLObjectParser implementation
95 // ************************************************************************
96
97 public String getParserDescription() {
98 return "This element returns a Gibbs operator for the joint distribution of population sizes.";
99 }
100
101 public Class getReturnType() {
102 return BayesianSkylineGibbsOperator.class;
103 }
104
105 public XMLSyntaxRule[] getSyntaxRules() {
106 return rules;
107 }
108
109 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
110 AttributeRule.newBooleanRule(LINEAR, true),
111 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
112 AttributeRule.newDoubleRule(LOWER),
113 AttributeRule.newDoubleRule(UPPER),
114 AttributeRule.newBooleanRule(JEFFREYS, true),
115 AttributeRule.newBooleanRule(REVERSE, true),
116 AttributeRule.newBooleanRule(EXPONENTIALMARKOV, true),
117 AttributeRule.newDoubleRule(SHAPE),
118 new ElementRule(BayesianSkylineLikelihood.class),
119 new ElementRule(Parameter.class)
120 };
121
122 }