Debian Codegraph @

src/dr/inferencexml/distribution/MixedDistributionLikelihoodParser.java

raw symbols SCIP
1 /*
2 * MixedDistributionLikelihoodParser.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.MixedDistributionLikelihood;
29 import dr.inference.distribution.ParametricDistributionModel;
30 import dr.inference.model.Statistic;
31 import dr.xml.*;
32
33 /**
34 * Reads a distribution likelihood from a DOM Document element.
35 */
36 public class MixedDistributionLikelihoodParser extends AbstractXMLObjectParser {
37 public static final String DISTRIBUTION_LIKELIHOOD = "mixedDistributionLikelihood";
38
39 public static final String DISTRIBUTION0 = "distribution0";
40 public static final String DISTRIBUTION1 = "distribution1";
41 public static final String DATA = "data";
42 public static final String INDICATORS = "indicators";
43
44 public String getParserName() {
45 return DISTRIBUTION_LIKELIHOOD;
46 }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50 XMLObject cxo0 = xo.getChild(DISTRIBUTION0);
51 ParametricDistributionModel model0 = (ParametricDistributionModel) cxo0.getChild(ParametricDistributionModel.class);
52
53 XMLObject cxo1 = xo.getChild(DISTRIBUTION1);
54 ParametricDistributionModel model1 = (ParametricDistributionModel) cxo1.getChild(ParametricDistributionModel.class);
55
56 Statistic data = (Statistic) ((XMLObject) xo.getChild(DATA)).getChild(Statistic.class);
57 Statistic indicators = (Statistic) ((XMLObject) xo.getChild(INDICATORS)).getChild(Statistic.class);
58
59 ParametricDistributionModel[] models = {model0, model1};
60 try {
61 return new MixedDistributionLikelihood(models, data, indicators);
62 } catch( Exception e) {
63 throw new XMLParseException(e.getMessage());
64 }
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(DISTRIBUTION0,
77 new XMLSyntaxRule[]{new ElementRule(ParametricDistributionModel.class)}),
78 new ElementRule(DISTRIBUTION1,
79 new XMLSyntaxRule[]{new ElementRule(ParametricDistributionModel.class)}),
80 new ElementRule(DATA, new XMLSyntaxRule[]{new ElementRule(Statistic.class)}),
81 new ElementRule(INDICATORS, new XMLSyntaxRule[]{new ElementRule(Statistic.class)}),
82 };
83
84 public String getParserDescription() {
85 return "Calculates the likelihood of some data given some mix of parametric distributions.";
86 }
87
88 public Class getReturnType() {
89 return MixedDistributionLikelihood.class;
90 }
91
92 }