Debian Codegraph @

src/dr/inferencexml/distribution/NegativeBinomialDistributionModelParser.java

raw symbols SCIP
1 /*
2 * NegativeBinomialDistributionModelParser.java
3 *
4 * Copyright (c) 2002-2016 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.NegativeBinomialDistributionModel;
29 import dr.inference.distribution.PoissonDistributionModel;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32
33 /**
34 * Reads a Poisson distribution model from a DOM Document element.
35 */
36 public class NegativeBinomialDistributionModelParser extends AbstractXMLObjectParser {
37
38 public static final String NEGATIVE_BINOMIAL_DISTRIBUTION_MODEL = "negativeBinomialDistributionModel";
39 public static final String MEAN = "mean";
40 public static final String ALPHA = "alpha";
41
42 public String getParserName() {
43 return NEGATIVE_BINOMIAL_DISTRIBUTION_MODEL;
44 }
45
46 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
47
48 Parameter meanParam, alphaParameter;
49
50 XMLObject cxo = xo.getChild(MEAN);
51 if (cxo.getChild(0) instanceof Parameter) {
52 meanParam = (Parameter) cxo.getChild(Parameter.class);
53 } else {
54 meanParam = new Parameter.Default(cxo.getDoubleChild(0));
55 }
56
57 cxo = xo.getChild(ALPHA);
58 if (cxo.getChild(0) instanceof Parameter) {
59 alphaParameter = (Parameter) cxo.getChild(Parameter.class);
60 } else {
61 alphaParameter = new Parameter.Default(cxo.getDoubleChild(0));
62 }
63
64 return new NegativeBinomialDistributionModel(meanParam, alphaParameter);
65 }
66
67 //************************************************************************
68 // AbstractXMLObjectParser implementation
69 //************************************************************************
70
71 public XMLSyntaxRule[] getSyntaxRules() {
72 return rules;
73 }
74
75 private final XMLSyntaxRule[] rules = {
76 new ElementRule(MEAN,
77 new XMLSyntaxRule[]{
78 new XORRule(
79 new ElementRule(Parameter.class),
80 new ElementRule(Double.class)
81 )}
82 ),
83 new ElementRule(ALPHA,
84 new XMLSyntaxRule[]{
85 new XORRule(
86 new ElementRule(Parameter.class),
87 new ElementRule(Double.class)
88 )}
89 )
90 };
91
92 public String getParserDescription() {
93 return "Describes a Negative Binomial distribution with a given mean and scale " +
94 "that can be used in a distributionLikelihood element";
95 }
96
97 public Class getReturnType() {
98 return NegativeBinomialDistributionModel.class;
99 }
100
101 }