Debian Codegraph @

src/dr/inferencexml/model/ThreadedCompoundLikelihoodParser.java

raw symbols SCIP
1 /*
2 * ThreadedCompoundLikelihoodParser.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.Likelihood;
29 import dr.inference.model.ThreadedCompoundLikelihood;
30 import dr.xml.*;
31
32 /**
33 *
34 */
35 public class ThreadedCompoundLikelihoodParser extends AbstractXMLObjectParser {
36
37 public static final String THREADED_COMPOUND_LIKELIHOOD = "threadedCompoundLikelihood";
38 public static final String WEIGHT = "robustWeight";
39
40 public String getParserName() {
41 return THREADED_COMPOUND_LIKELIHOOD;
42 }
43
44 public String[] getParserNames() {
45 return new String[]{getParserName()};
46 }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50 ThreadedCompoundLikelihood compoundLikelihood = new ThreadedCompoundLikelihood();
51
52 for (int i = 0; i < xo.getChildCount(); i++) {
53 if (xo.getChild(i) instanceof Likelihood) {
54 compoundLikelihood.addLikelihood((Likelihood) xo.getChild(i));
55 } else {
56
57 Object rogueElement = xo.getChild(i);
58
59 throw new XMLParseException("An element (" + rogueElement + ") which is not a likelihood has been added to a " + THREADED_COMPOUND_LIKELIHOOD + " element");
60 }
61 }
62
63 double weight = xo.getAttribute(WEIGHT, 0.0);
64 if (weight < 0)
65 throw new XMLParseException("Robust weight must be non-negative.");
66 compoundLikelihood.setWeightFactor(Math.exp(-weight));
67
68 return compoundLikelihood;
69 }
70
71 //************************************************************************
72 // AbstractXMLObjectParser implementation
73 //************************************************************************
74
75 public String getParserDescription() {
76 return "A likelihood function which is simply the product of its component likelihood functions.";
77 }
78
79 public XMLSyntaxRule[] getSyntaxRules() {
80 return rules;
81 }
82
83 private final XMLSyntaxRule[] rules = {
84 new ElementRule(Likelihood.class, 1, Integer.MAX_VALUE),
85 AttributeRule.newDoubleRule(WEIGHT, true),
86 };
87
88 public Class getReturnType() {
89 return ThreadedCompoundLikelihood.class;
90 }
91 }