| 1 | package dr.inferencexml.operators; |
| 2 | |
| 3 | import dr.inference.distribution.DistributionLikelihood; |
| 4 | import dr.inference.distribution.IndependentInverseGammaDistributionModel; |
| 5 | import dr.inference.distribution.ShrinkageGibbsOperator; |
| 6 | import dr.inference.model.Parameter; |
| 7 | import dr.inference.operators.ShrinkageAugmentedGibbsOperator; |
| 8 | import dr.xml.*; |
| 9 | |
| 10 | public class ShrinkageAugmentedGibbsOperatorParser extends AbstractXMLObjectParser{ |
| 11 | public final static String LOCAL = "local"; |
| 12 | public final static String GLOBAL = "global"; |
| 13 | public final static String SHRINKAGE_AUGMENTED_GIBBS_OPERATOR = "shrinkageAugmentedGibbsOperator"; |
| 14 | public final static String WEIGHT = "weight"; |
| 15 | |
| 16 | @Override |
| 17 | public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 18 | double weight = xo.getDoubleAttribute(WEIGHT); |
| 19 | XMLObject local = xo.getChild(LOCAL); |
| 20 | XMLObject global = xo.getChild(GLOBAL); |
| 21 | |
| 22 | IndependentInverseGammaDistributionModel localPrior = (IndependentInverseGammaDistributionModel) local.getChild(IndependentInverseGammaDistributionModel.class); |
| 23 | DistributionLikelihood localAugmentedPrior = (DistributionLikelihood) local.getChild(DistributionLikelihood.class); |
| 24 | |
| 25 | IndependentInverseGammaDistributionModel globalPrior = (IndependentInverseGammaDistributionModel) global.getChild(IndependentInverseGammaDistributionModel.class); |
| 26 | DistributionLikelihood globalAugmentedPrior = (DistributionLikelihood) global.getChild(DistributionLikelihood.class); |
| 27 | |
| 28 | |
| 29 | |
| 30 | return new ShrinkageAugmentedGibbsOperator(weight, localAugmentedPrior, globalAugmentedPrior, localPrior, globalPrior); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public XMLSyntaxRule[] getSyntaxRules() { |
| 35 | return rules; |
| 36 | } |
| 37 | |
| 38 | XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 39 | AttributeRule.newDoubleRule(WEIGHT), |
| 40 | new ElementRule(LOCAL, new XMLSyntaxRule[]{ |
| 41 | new ElementRule(IndependentInverseGammaDistributionModel.class), |
| 42 | new ElementRule(DistributionLikelihood.class) |
| 43 | }), |
| 44 | new ElementRule(GLOBAL, new XMLSyntaxRule[]{ |
| 45 | new ElementRule(IndependentInverseGammaDistributionModel.class), |
| 46 | new ElementRule(DistributionLikelihood.class) |
| 47 | }), |
| 48 | }; |
| 49 | |
| 50 | @Override |
| 51 | public String getParserDescription() { |
| 52 | return "Gibbs sampler for augmented portions of a shrinkage prior"; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public Class getReturnType() { |
| 57 | return ShrinkageGibbsOperator.class; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String getParserName() { |
| 62 | return SHRINKAGE_AUGMENTED_GIBBS_OPERATOR; |
| 63 | } |
| 64 | } |