| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inferencexml.distribution; |
| 27 |
|
| 28 |
import dr.inference.distribution.UniformDistributionModel; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class UniformDistributionModelParser extends AbstractXMLObjectParser { |
| 36 |
|
| 37 |
public static final String UNIFORM_DISTRIBUTION_MODEL = "uniformDistributionModel"; |
| 38 |
public static final String LOWER = "lower"; |
| 39 |
public static final String UPPER = "upper"; |
| 40 |
|
| 41 |
public String getParserName() { |
| 42 |
return UNIFORM_DISTRIBUTION_MODEL; |
| 43 |
} |
| 44 |
|
| 45 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 46 |
|
| 47 |
Parameter upperParam; |
| 48 |
Parameter lowerParam; |
| 49 |
|
| 50 |
XMLObject cxo = xo.getChild(LOWER); |
| 51 |
if (cxo.getChild(0) instanceof Parameter) { |
| 52 |
lowerParam = (Parameter) cxo.getChild(Parameter.class); |
| 53 |
} else { |
| 54 |
lowerParam = new Parameter.Default(cxo.getDoubleChild(0)); |
| 55 |
} |
| 56 |
|
| 57 |
cxo = xo.getChild(UPPER); |
| 58 |
if (cxo.getChild(0) instanceof Parameter) { |
| 59 |
upperParam = (Parameter) cxo.getChild(Parameter.class); |
| 60 |
} else { |
| 61 |
upperParam = new Parameter.Default(cxo.getDoubleChild(0)); |
| 62 |
} |
| 63 |
|
| 64 |
return new UniformDistributionModel(lowerParam, upperParam); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 72 |
return rules; |
| 73 |
} |
| 74 |
|
| 75 |
private final XMLSyntaxRule[] rules = { |
| 76 |
new ElementRule(LOWER, |
| 77 |
new XMLSyntaxRule[]{ |
| 78 |
new XORRule( |
| 79 |
new ElementRule(Parameter.class), |
| 80 |
new ElementRule(Double.class) |
| 81 |
)} |
| 82 |
), |
| 83 |
new ElementRule(UPPER, |
| 84 |
new XMLSyntaxRule[]{ |
| 85 |
new XORRule( |
| 86 |
new ElementRule(Parameter.class), |
| 87 |
new ElementRule(Double.class) |
| 88 |
)} |
| 89 |
) |
| 90 |
}; |
| 91 |
|
| 92 |
public String getParserDescription() { |
| 93 |
return "Describes a uniform distribution with a given lower and upper bounds "; |
| 94 |
} |
| 95 |
|
| 96 |
public Class getReturnType() { |
| 97 |
return UniformDistributionModel.class; |
| 98 |
} |
| 99 |
} |