Debian Codegraph @

src/dr/inferencexml/distribution/TruncatedDistributionLikelihoodParser.java

raw symbols SCIP
1 package dr.inferencexml.distribution;
2
3 import dr.inference.distribution.DistributionLikelihood;
4 import dr.inference.model.Parameter;
5 import dr.inference.model.TruncatedDistributionLikelihood;
6 import dr.xml.*;
7
8 /**
9 * @author Max Tolkoff
10 */
11 public class TruncatedDistributionLikelihoodParser extends AbstractXMLObjectParser {
12 public static final String TRUNCATED_DISTRIBUTION_LIKELIHOOD = "truncatedDistributionLikelihood";
13 public static final String LOW = "low";
14 public static final String HIGH = "high";
15
16 @Override
17 public String getParserName() {
18 return TRUNCATED_DISTRIBUTION_LIKELIHOOD;
19 }
20
21 @Override
22 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
23 DistributionLikelihood likelihood = (DistributionLikelihood) xo.getChild(DistributionLikelihood.class);
24 Parameter low;
25 Parameter high;
26 if(xo.getChild(LOW) != null){
27 low = (Parameter) xo.getChild(LOW).getChild(Parameter.class);
28 }
29 else{
30 low = new Parameter.Default("low", Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
31 }
32 if(xo.getChild(HIGH) != null){
33 high = (Parameter) xo.getChild(HIGH).getChild(Parameter.class);
34 }
35 else{
36 high = new Parameter.Default("high", Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
37 }
38
39 return new TruncatedDistributionLikelihood(likelihood, low, high);
40 }
41
42 @Override
43 public XMLSyntaxRule[] getSyntaxRules() {
44 return rules;
45 }
46
47 @Override
48 public String getParserDescription() {
49 return "Produces a truncated distribution likelihood";
50 }
51
52 @Override
53 public Class getReturnType() {
54 return TruncatedDistributionLikelihood.class;
55 }
56
57 private final XMLSyntaxRule[] rules = {
58 new ElementRule(DistributionLikelihood.class),
59 new ElementRule(LOW, new XMLSyntaxRule[]{
60 new ElementRule(Parameter.class)
61 }, true),
62 new ElementRule(HIGH, new XMLSyntaxRule[]{
63 new ElementRule(Parameter.class)
64 }, true),
65 };
66 }