Debian Codegraph @

src/dr/inferencexml/distribution/MomentDistributionModelParser.java

raw symbols SCIP
1 /*
2 * MomentDistributionModelParser.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.MomentDistributionModel;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 /**
33 * Created by max on 5/14/15.
34 */
35 public class MomentDistributionModelParser extends AbstractXMLObjectParser {
36 public static final String MOMENT_DISTRIBUTION_MODEL = "momentDistributionModel";
37 public static final String MEAN = "mean";
38 // public static final String STDEV = "stdev";
39 public static final String PREC = "precision";
40 public static final String CUTOFF="cutoff";
41 public static final String DATA="data";
42
43 @Override
44 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
45 Parameter mean=(Parameter) xo.getChild(MEAN).getChild(0);
46 Parameter prec=(Parameter) xo.getChild(PREC).getChild(0);
47 Parameter cutoff=null;
48 if(xo.getChild(CUTOFF) != null){
49 cutoff=(Parameter) xo.getChild(CUTOFF).getChild(0);}
50 Parameter data=(Parameter) xo.getChild(DATA).getChild(0);
51 String id = xo.getId();
52
53 return new MomentDistributionModel(id, mean, prec, cutoff, data);
54 }
55
56 @Override
57 public XMLSyntaxRule[] getSyntaxRules() {
58 return rules;
59 }
60
61 private final XMLSyntaxRule[] rules = {
62 new ElementRule(MEAN,
63 new XMLSyntaxRule[]{
64 new ElementRule(Parameter.class)
65 }
66 ),
67 new ElementRule(CUTOFF,
68 new XMLSyntaxRule[]{
69 new ElementRule(Parameter.class, true)
70 },true
71 ),
72 new ElementRule(PREC,
73 new XMLSyntaxRule[]{
74 new ElementRule(Parameter.class)
75 }
76 ),
77 new ElementRule(DATA,
78 new XMLSyntaxRule[]{
79 new ElementRule(Parameter.class)
80 }
81 )
82 };
83
84 @Override
85 public String getParserDescription() {
86 return "Returns an internally truncated normal distribution for claculating a moment prior";
87 }
88
89 @Override
90 public Class getReturnType() {
91 return MomentDistributionModel.class;
92 }
93
94 @Override
95 public String getParserName() {
96 return MOMENT_DISTRIBUTION_MODEL;
97 }
98 }