| 1 | package dr.inferencexml.operators; |
| 2 | |
| 3 | import dr.inference.distribution.IndependentInverseGammaDistributionModel; |
| 4 | import dr.inference.distribution.ShrinkageGibbsOperator; |
| 5 | import dr.inference.model.Parameter; |
| 6 | import dr.xml.*; |
| 7 | |
| 8 | public class ShrinkageGibbsOperatorParser extends AbstractXMLObjectParser{ |
| 9 | private final static String SHRINKAGE_GIBBS_OPERATOR = "shrinkageGibbsOperator"; |
| 10 | private final static String LOCAL_PRIOR = "localPrior"; |
| 11 | private final static String GLOBAL_PRIOR = "globalPrior"; |
| 12 | private final static String DATA = "data"; |
| 13 | private final static String WEIGHT = "weight"; |
| 14 | |
| 15 | @Override |
| 16 | public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 17 | IndependentInverseGammaDistributionModel localPrior = (IndependentInverseGammaDistributionModel) xo.getChild(LOCAL_PRIOR).getChild(IndependentInverseGammaDistributionModel.class); |
| 18 | IndependentInverseGammaDistributionModel globalPrior = (IndependentInverseGammaDistributionModel) xo.getChild(GLOBAL_PRIOR).getChild(IndependentInverseGammaDistributionModel.class); |
| 19 | Parameter data = (Parameter) xo.getChild(DATA).getChild(Parameter.class); |
| 20 | |
| 21 | double weight = xo.getDoubleAttribute(WEIGHT); |
| 22 | |
| 23 | |
| 24 | return new ShrinkageGibbsOperator(weight, localPrior, globalPrior, data); |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public XMLSyntaxRule[] getSyntaxRules() { |
| 29 | return rules; |
| 30 | } |
| 31 | |
| 32 | XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 33 | AttributeRule.newDoubleRule(WEIGHT), |
| 34 | new ElementRule(LOCAL_PRIOR, new XMLSyntaxRule[]{ |
| 35 | new ElementRule(IndependentInverseGammaDistributionModel.class) |
| 36 | }), |
| 37 | new ElementRule(GLOBAL_PRIOR, new XMLSyntaxRule[]{ |
| 38 | new ElementRule(IndependentInverseGammaDistributionModel.class) |
| 39 | }), |
| 40 | new ElementRule(DATA, new XMLSyntaxRule[]{ |
| 41 | new ElementRule(Parameter.class) |
| 42 | }) |
| 43 | }; |
| 44 | |
| 45 | @Override |
| 46 | public String getParserDescription() { |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Class getReturnType() { |
| 52 | return ShrinkageGibbsOperator.class; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String getParserName() { |
| 57 | return SHRINKAGE_GIBBS_OPERATOR; |
| 58 | } |
| 59 | } |