Debian Codegraph @

src/dr/inferencexml/model/OneOnX3PriorParser.java

raw symbols SCIP
1 /*
2 * OneOnX3PriorParser.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.model;
27
28 import dr.xml.*;
29 import dr.inference.model.Statistic;
30 import dr.inference.model.OneOnX3Prior;
31
32 /**
33 * @author Chieh-Hsi Wu
34 *
35 * Parser of OneOnX3Prior
36 *
37 */
38
39
40 public class OneOnX3PriorParser extends AbstractXMLObjectParser {
41
42 public static final String ONE_ONE_X_3_PRIOR = "oneOnX3Prior";
43 public static final String DATA = "data";
44
45 public String getParserName() {
46 return ONE_ONE_X_3_PRIOR;
47 }
48
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 OneOnX3Prior likelihood = new OneOnX3Prior();
53
54 XMLObject cxo = xo;
55
56 if (xo.hasChildNamed(DATA)) {
57 cxo = xo.getChild(DATA);
58 }
59
60 for (int i = 0; i < cxo.getChildCount(); i++) {
61 if (cxo.getChild(i) instanceof Statistic) {
62 likelihood.addData((Statistic) cxo.getChild(i));
63 }
64 }
65
66 return likelihood;
67 }
68
69 //************************************************************************
70 // AbstractXMLObjectParser implementation
71 //************************************************************************
72
73 public XMLSyntaxRule[] getSyntaxRules() {
74 return rules;
75 }
76
77 private final XMLSyntaxRule[] rules = {
78 new XORRule(
79 new ElementRule(Statistic.class, 1, Integer.MAX_VALUE),
80 new ElementRule(DATA, new XMLSyntaxRule[]{new ElementRule(Statistic.class, 1, Integer.MAX_VALUE)})
81 )
82 };
83
84 public String getParserDescription() {
85 return "Calculates the (improper) prior proportional to Prod_i (1/x_i^3) for the given statistic x.";
86 }
87
88 public Class getReturnType() {
89 return OneOnX3Prior.class;
90 }
91 }
92