| 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.MixedDistributionLikelihood; |
| 29 |
import dr.inference.distribution.ParametricDistributionModel; |
| 30 |
import dr.inference.model.Statistic; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class MixedDistributionLikelihoodParser extends AbstractXMLObjectParser { |
| 37 |
public static final String DISTRIBUTION_LIKELIHOOD = "mixedDistributionLikelihood"; |
| 38 |
|
| 39 |
public static final String DISTRIBUTION0 = "distribution0"; |
| 40 |
public static final String DISTRIBUTION1 = "distribution1"; |
| 41 |
public static final String DATA = "data"; |
| 42 |
public static final String INDICATORS = "indicators"; |
| 43 |
|
| 44 |
public String getParserName() { |
| 45 |
return DISTRIBUTION_LIKELIHOOD; |
| 46 |
} |
| 47 |
|
| 48 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 49 |
|
| 50 |
XMLObject cxo0 = xo.getChild(DISTRIBUTION0); |
| 51 |
ParametricDistributionModel model0 = (ParametricDistributionModel) cxo0.getChild(ParametricDistributionModel.class); |
| 52 |
|
| 53 |
XMLObject cxo1 = xo.getChild(DISTRIBUTION1); |
| 54 |
ParametricDistributionModel model1 = (ParametricDistributionModel) cxo1.getChild(ParametricDistributionModel.class); |
| 55 |
|
| 56 |
Statistic data = (Statistic) ((XMLObject) xo.getChild(DATA)).getChild(Statistic.class); |
| 57 |
Statistic indicators = (Statistic) ((XMLObject) xo.getChild(INDICATORS)).getChild(Statistic.class); |
| 58 |
|
| 59 |
ParametricDistributionModel[] models = {model0, model1}; |
| 60 |
try { |
| 61 |
return new MixedDistributionLikelihood(models, data, indicators); |
| 62 |
} catch( Exception e) { |
| 63 |
throw new XMLParseException(e.getMessage()); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 72 |
return rules; |
| 73 |
} |
| 74 |
|
| 75 |
private final XMLSyntaxRule[] rules = { |
| 76 |
new ElementRule(DISTRIBUTION0, |
| 77 |
new XMLSyntaxRule[]{new ElementRule(ParametricDistributionModel.class)}), |
| 78 |
new ElementRule(DISTRIBUTION1, |
| 79 |
new XMLSyntaxRule[]{new ElementRule(ParametricDistributionModel.class)}), |
| 80 |
new ElementRule(DATA, new XMLSyntaxRule[]{new ElementRule(Statistic.class)}), |
| 81 |
new ElementRule(INDICATORS, new XMLSyntaxRule[]{new ElementRule(Statistic.class)}), |
| 82 |
}; |
| 83 |
|
| 84 |
public String getParserDescription() { |
| 85 |
return "Calculates the likelihood of some data given some mix of parametric distributions."; |
| 86 |
} |
| 87 |
|
| 88 |
public Class getReturnType() { |
| 89 |
return MixedDistributionLikelihood.class; |
| 90 |
} |
| 91 |
|
| 92 |
} |