| 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.evomodelxml.operators; |
| 27 |
|
| 28 |
import dr.evomodel.operators.GibbsPruneAndRegraft; |
| 29 |
import dr.evomodel.tree.TreeModel; |
| 30 |
import dr.inference.operators.MCMCOperator; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class GibbsPruneAndRegraftParser extends AbstractXMLObjectParser { |
| 36 |
|
| 37 |
public static final String GIBBS_PRUNE_AND_REGRAFT = "GibbsPruneAndRegraft"; |
| 38 |
|
| 39 |
public String getParserName() { |
| 40 |
return GIBBS_PRUNE_AND_REGRAFT; |
| 41 |
} |
| 42 |
|
| 43 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 44 |
|
| 45 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 46 |
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 47 |
boolean pruned = true; |
| 48 |
if (xo.hasAttribute("pruned")) { |
| 49 |
pruned = xo.getBooleanAttribute("pruned"); |
| 50 |
} |
| 51 |
|
| 52 |
return new GibbsPruneAndRegraft(treeModel, pruned, weight); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public String getParserDescription() { |
| 60 |
return "This element represents a Gibbs sampler implemented through a prune and regraft operator. " |
| 61 |
+ "This operator prunes a random subtree and regrafts it below a node chosen by an importance distribution which is the proportion of the likelihoods of the proposals."; |
| 62 |
} |
| 63 |
|
| 64 |
public Class getReturnType() { |
| 65 |
return GibbsPruneAndRegraft.class; |
| 66 |
} |
| 67 |
|
| 68 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 69 |
return rules; |
| 70 |
} |
| 71 |
|
| 72 |
private final XMLSyntaxRule[] rules; |
| 73 |
|
| 74 |
{ |
| 75 |
rules = new XMLSyntaxRule[]{ |
| 76 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 77 |
AttributeRule.newBooleanRule("pruned"), |
| 78 |
new ElementRule(TreeModel.class)}; |
| 79 |
} |
| 80 |
|
| 81 |
} |