Debian Codegraph @

src/dr/inferencexml/model/IndianBuffetProcessPriorParser.java

raw symbols SCIP
1 /*
2 * IndianBuffetProcessPriorParser.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.inference.model.AdaptableSizeFastMatrixParameter;
29 import dr.inference.model.IndianBuffetProcessPrior;
30 import dr.inference.model.MatrixParameter;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 /**
35 * @author Max Tolkoff
36 */
37 public class IndianBuffetProcessPriorParser extends AbstractXMLObjectParser {
38 public static final String INDIAN_BUFFET_PROCESS="indianBuffetProcess";
39 public static final String BETA="beta";
40 public static final String ALPHA="alpha";
41 public static final String DATA="data";
42
43
44 @Override
45 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
46 Parameter alpha=(Parameter) xo.getChild(ALPHA).getChild(0);
47 AdaptableSizeFastMatrixParameter data=(AdaptableSizeFastMatrixParameter) xo.getChild(DATA).getChild(0);
48 Parameter beta;
49 if(xo.hasChildNamed(BETA))
50 {
51 beta=(Parameter) xo.getChild(BETA).getChild(0);
52 }
53 else
54 {
55 beta=new Parameter.Default(1);
56 }
57 return new IndianBuffetProcessPrior(alpha, beta, data);
58 }
59
60 @Override
61 public XMLSyntaxRule[] getSyntaxRules() {
62 return rules;
63 }
64
65 private final XMLSyntaxRule[] rules = {
66 new ElementRule(BETA,
67 new XMLSyntaxRule[]{
68 new ElementRule(Parameter.class)
69 }
70 , true),
71 new ElementRule(ALPHA,
72 new XMLSyntaxRule[]{
73 new ElementRule(Parameter.class)
74 }
75 ),
76 new ElementRule(DATA,
77 new XMLSyntaxRule[]{
78 new ElementRule(AdaptableSizeFastMatrixParameter.class)
79 }
80 )
81 };
82
83 @Override
84 public String getParserDescription() {
85 return "Indian Buffet Process prior on a binary matrix parameter";
86 }
87
88 @Override
89 public Class getReturnType() {
90 return IndianBuffetProcessPrior.class;
91 }
92
93 @Override
94 public String getParserName() {
95 return INDIAN_BUFFET_PROCESS;
96 }
97 }