Debian Codegraph @

src/dr/inferencexml/distribution/TDistributionModelParser.java

raw symbols SCIP
1 /*
2 * TDistributionModelParser.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.TDistributionModel;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 /**
33 * Reads a normal distribution model from a DOM Document element.
34 */
35 public class TDistributionModelParser extends AbstractXMLObjectParser {
36
37 public static final String T_DISTRIBUTION_MODEL = "tDistributionModel";
38 public static final String LOCATION = "location";
39 public static final String SCALE = "scale";
40 public static final String DF = "df";
41
42 public String getParserName() {
43 return T_DISTRIBUTION_MODEL;
44 }
45
46 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
47
48 Parameter locationParam;
49 Parameter scaleParam;
50 Parameter dfParam;
51
52 XMLObject cxo = xo.getChild(LOCATION);
53 if (cxo.getChild(0) instanceof Parameter) {
54 locationParam = (Parameter) cxo.getChild(Parameter.class);
55 } else {
56 locationParam = new Parameter.Default(cxo.getDoubleChild(0));
57 }
58
59 cxo = xo.getChild(SCALE);
60 if (cxo.getChild(0) instanceof Parameter) {
61 scaleParam = (Parameter) cxo.getChild(Parameter.class);
62 } else {
63 scaleParam = new Parameter.Default(cxo.getDoubleChild(0));
64 }
65
66
67 cxo = xo.getChild(DF);
68 if (cxo.getChild(0) instanceof Parameter) {
69 dfParam = (Parameter) cxo.getChild(Parameter.class);
70 } else {
71 dfParam = new Parameter.Default(cxo.getDoubleChild(0));
72 }
73 return new TDistributionModel(locationParam, scaleParam, dfParam);
74 }
75
76 //************************************************************************
77 // AbstractXMLObjectParser implementation
78 //************************************************************************
79
80 public XMLSyntaxRule[] getSyntaxRules() {
81 return rules;
82 }
83
84 private final XMLSyntaxRule[] rules = {
85 new ElementRule(LOCATION,
86 new XMLSyntaxRule[]{
87 new XORRule(
88 new ElementRule(Parameter.class),
89 new ElementRule(Double.class)
90 )}
91 ),
92 new ElementRule(SCALE,
93 new XMLSyntaxRule[]{
94 new XORRule(
95 new ElementRule(Parameter.class),
96 new ElementRule(Double.class)
97 )}
98 ),
99 new ElementRule(DF,
100 new XMLSyntaxRule[]{
101 new XORRule(
102 new ElementRule(Parameter.class),
103 new ElementRule(Double.class)
104 )}
105 )
106 };
107
108 public String getParserDescription() {
109 return "Describes a normal distribution with a given mean and standard deviation " +
110 "that can be used in a distributionLikelihood element";
111 }
112
113 public Class getReturnType() {
114 return TDistributionModel.class;
115 }
116
117 }