Debian Codegraph @

src/dr/inferencexml/distribution/CachedDistributionLikelihoodParser.java

raw symbols SCIP
1 /*
2 * CachedDistributionLikelihoodParser.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.AbstractDistributionLikelihood;
29 import dr.inference.distribution.CachedDistributionLikelihood;
30 import dr.inference.distribution.DistributionLikelihood;
31 import dr.inference.model.Variable;
32 import dr.xml.*;
33
34 import java.util.logging.Logger;
35
36 /**
37 * @author Marc Suchard
38 */
39 public class CachedDistributionLikelihoodParser extends AbstractXMLObjectParser {
40
41 public static final String CACHED_PRIOR = "cachedPrior";
42
43 // public static final String RATE_BLOCK = "rates";
44 //public static final String INDICATOR_BLOCK = "indicators";
45
46 public String getParserName() {
47 return CACHED_PRIOR;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 final String name = xo.hasId() ? xo.getId() : CACHED_PRIOR;
53
54 final AbstractDistributionLikelihood likelihood = (AbstractDistributionLikelihood) xo.getChild(AbstractDistributionLikelihood.class);
55 final Variable variable = (Variable) xo.getChild(Variable.class);
56
57 final Logger logger = Logger.getLogger("dr.inference");
58 logger.info("Constructing a cache around likelihood '" + likelihood.getId() + "', signal = " + variable.getVariableName());
59
60 return new CachedDistributionLikelihood(name, likelihood, variable);
61
62 }
63
64 //************************************************************************
65 // AbstractXMLObjectParser implementation
66 //************************************************************************
67
68 public XMLSyntaxRule[] getSyntaxRules() {
69 return rules;
70 }
71
72 private final XMLSyntaxRule[] rules = {
73 new ElementRule(AbstractDistributionLikelihood.class),
74 new ElementRule(Variable.class),
75 };
76
77 public String getParserDescription() {
78 return "Calculates a cached likelihood of some data given some parametric or empirical distribution.";
79 }
80
81 public Class getReturnType() {
82 return DistributionLikelihood.class;
83 }
84 }