Debian Codegraph @

src/dr/inferencexml/distribution/TwoPartsDistributionLikelihoodParser.java

raw symbols SCIP
1 /*
2 * TwoPartsDistributionLikelihoodParser.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.DistributionLikelihood;
29 import dr.inference.distribution.TwoPartsDistributionLikelihood;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32 import dr.math.distributions.Distribution;
33
34 /**
35 * @author Chieh-Hsi Wu
36 *
37 * Parser for TwoPartDistribution likelihood
38 */
39 public class TwoPartsDistributionLikelihoodParser extends AbstractXMLObjectParser{
40 public static final String TWO_PART_DISTRIBUTION_LIKELIHOOD = "twoPartDistribution";
41 public static final String PRIOR = "priorLik";
42 public static final String PSEUDO_PRIOR = "pseudoPriorLik";
43 public static final String PARAMETER_VECTOR = "parameterVector";
44 public static final String PARAMETER_INDEX = "paramIndex";
45 public static final String SELECTED_VARIABLE = "selectedVariable";
46
47
48 public String getParserName() {
49 return TWO_PART_DISTRIBUTION_LIKELIHOOD;
50 }
51
52 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
53 DistributionLikelihood priorLikelihood = (DistributionLikelihood)xo.getElementFirstChild(PRIOR);
54 DistributionLikelihood pseudoPriorLikelihood = (DistributionLikelihood)xo.getElementFirstChild(PSEUDO_PRIOR);
55 Distribution prior = priorLikelihood.getDistribution();
56 Distribution pseudoPrior = pseudoPriorLikelihood.getDistribution();
57 Parameter bitVector = (Parameter)xo.getElementFirstChild(PARAMETER_VECTOR);
58 int paramIndex = xo.getIntegerAttribute(PARAMETER_INDEX);
59 Parameter selectedVariable = (Parameter)xo.getElementFirstChild(SELECTED_VARIABLE);
60
61
62 TwoPartsDistributionLikelihood likelihood =
63 new TwoPartsDistributionLikelihood(
64 prior,
65 pseudoPrior,
66 bitVector,
67 paramIndex
68 );
69 likelihood.addData(selectedVariable);
70
71 return likelihood;
72 }
73
74 //************************************************************************
75 // AbstractXMLObjectParser implementation
76 //************************************************************************
77
78 public XMLSyntaxRule[] getSyntaxRules() {
79 return rules;
80 }
81
82 private final XMLSyntaxRule[] rules = {
83
84 };
85
86 public String getParserDescription() {
87 return "Calculates the likelihood of some data given some parametric or empirical distribution.";
88 }
89
90 public Class getReturnType() {
91 return TwoPartsDistributionLikelihood.class;
92 }
93 }