Debian Codegraph @

src/dr/inferencexml/distribution/ExponentialMarkovModelParser.java

raw symbols SCIP
1 /*
2 * ExponentialMarkovModelParser.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.distribution;
27
28 import dr.inference.distribution.ExponentialMarkovModel;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 /**
33 */
34 public class ExponentialMarkovModelParser extends AbstractXMLObjectParser {
35
36 public static final String CHAIN_PARAMETER = "chainParameter";
37 public static final String JEFFREYS = "jeffreys";
38 public static final String REVERSE = "reverse";
39 public static final String SHAPE = "shape";
40
41
42 public String getParserName() {
43 return ExponentialMarkovModel.EXPONENTIAL_MARKOV_MODEL;
44 }
45
46 /**
47 * Reads a gamma distribution model from a DOM Document element.
48 */
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 XMLObject object = xo.getChild(CHAIN_PARAMETER);
52
53 Parameter chainParameter = (Parameter) object.getChild(0);
54
55 boolean jeffreys = xo.getAttribute(JEFFREYS, false);
56 boolean reverse = xo.getAttribute(REVERSE, false);
57
58 double shape = xo.getAttribute(SHAPE, 1.0);
59 if (shape < 1.0) {
60 throw new XMLParseException("ExponentialMarkovModel: shape parameter must be >= 1.0");
61 }
62
63 if (shape == 1.0) {
64 System.out.println("Exponential markov model on parameter " +
65 chainParameter.getParameterName() + " (jeffreys=" + jeffreys + ", reverse=" +
66 reverse + ")");
67 } else {
68 System.out.println("Gamma markov model on parameter " +
69 chainParameter.getParameterName() + " (jeffreys=" + jeffreys + ", reverse=" +
70 reverse + " shape=" + shape + ")");
71 }
72
73 return new ExponentialMarkovModel(chainParameter, jeffreys, reverse, shape);
74 }
75
76 public String getParserDescription() {
77 return "A continuous state, discrete time markov chain in which each new state is an " +
78 "exponentially distributed variable with a mean of the previous state.";
79 }
80
81 public Class getReturnType() {
82 return ExponentialMarkovModel.class;
83 }
84
85 public XMLSyntaxRule[] getSyntaxRules() {
86 return rules;
87 }
88
89 private final XMLSyntaxRule[] rules = {
90 AttributeRule.newBooleanRule(JEFFREYS, true),
91 AttributeRule.newBooleanRule(REVERSE, true),
92 new ElementRule(CHAIN_PARAMETER, Parameter.class)
93 };
94 }