Debian Codegraph @

src/dr/inferencexml/distribution/LocationScaleJeffreysPriorParser.java

raw symbols SCIP
1 /*
2 * LocationScaleJeffreysPriorParser.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.LocationScaleJeffreysPrior;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 /**
33 * @author Marc A. Suchard
34 * @author Robert E. Weiss
35 */
36 public class LocationScaleJeffreysPriorParser extends AbstractXMLObjectParser {
37
38 public static final String PARSER_NAME = "locationScaleJeffreysPrior";
39 public static final String LOCATION = TwoPieceLocationScaleDistributionModelParser.LOCATION;
40 public static final String SIGMA = TwoPieceLocationScaleDistributionModelParser.SIGMA;
41 public static final String GAMMA = TwoPieceLocationScaleDistributionModelParser.GAMMA;
42 public static final String PARAMETERIZATION = TwoPieceLocationScaleDistributionModelParser.PARAMETERIZATION;
43
44 public static final String ALPHA_0 = "alpha0";
45 public static final String BETA_0 = "beta0";
46
47 public String getParserName() {
48 return PARSER_NAME;
49 }
50
51 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
52
53 Parameter location = (Parameter) xo.getChild(LOCATION).getChild(Parameter.class);
54 Parameter sigma = (Parameter) xo.getChild(SIGMA).getChild(Parameter.class);
55 Parameter gamma = (Parameter) xo.getChild(GAMMA).getChild(Parameter.class);
56
57 Parameter alpha0 = (Parameter) xo.getChild(ALPHA_0).getChild(Parameter.class);
58 Parameter beta0 = (Parameter) xo.getChild(BETA_0).getChild(Parameter.class);
59
60 String typeString = xo.getStringAttribute(PARAMETERIZATION);
61 LocationScaleJeffreysPrior.Type type = LocationScaleJeffreysPrior.Type.parseFromString(
62 typeString
63 );
64 if (type == null) {
65 throw new XMLParseException("Unable to parse location-scale Jeffrey priors type " + typeString);
66 }
67
68 return new LocationScaleJeffreysPrior(location, sigma, gamma, alpha0, beta0, type);
69 }
70
71 //************************************************************************
72 // AbstractXMLObjectParser implementation
73 //************************************************************************
74
75 public XMLSyntaxRule[] getSyntaxRules() {
76 return rules;
77 }
78
79 private final XMLSyntaxRule[] rules = {
80 AttributeRule.newStringArrayRule(PARAMETERIZATION),
81 new ElementRule(LOCATION,
82 new XMLSyntaxRule[]{
83 new ElementRule(Parameter.class),
84 }),
85 new ElementRule(SIGMA,
86 new XMLSyntaxRule[]{
87 new ElementRule(Parameter.class),
88 }),
89 new ElementRule(GAMMA,
90 new XMLSyntaxRule[]{
91 new ElementRule(Parameter.class),
92 }),
93 new ElementRule(ALPHA_0,
94 new XMLSyntaxRule[]{
95 new ElementRule(Parameter.class),
96 }, true),
97
98 new ElementRule(BETA_0,
99 new XMLSyntaxRule[]{
100 new ElementRule(Parameter.class),
101 }, true),
102 };
103
104 public String getParserDescription() {
105 return "Calculates the likelihood of hyperparameters of the two-piece location-scale model.";
106 }
107
108 public Class getReturnType() {
109 return LocationScaleJeffreysPrior.class;
110 }
111 }