| 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.SubtreeLeapOperator; |
| 29 |
import dr.evomodel.tree.TreeModel; |
| 30 |
import dr.inference.operators.AdaptableMCMCOperator; |
| 31 |
import dr.inference.operators.AdaptationMode; |
| 32 |
import dr.inference.operators.MCMCOperator; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class SubtreeLeapOperatorParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String SUBTREE_LEAP = "subtreeLeap"; |
| 40 |
|
| 41 |
public static final String SIZE = "size"; |
| 42 |
public static final String TARGET_ACCEPTANCE = "targetAcceptance"; |
| 43 |
|
| 44 |
public String getParserName() { |
| 45 |
return SUBTREE_LEAP; |
| 46 |
} |
| 47 |
|
| 48 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 49 |
|
| 50 |
AdaptationMode mode = AdaptationMode.parseMode(xo); |
| 51 |
|
| 52 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 53 |
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 54 |
|
| 55 |
|
| 56 |
final double size = xo.getAttribute(SIZE, Double.NaN); |
| 57 |
final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234); |
| 58 |
|
| 59 |
if (size <= 0.0) { |
| 60 |
throw new XMLParseException("The SubTreeLeap size attribute must be positive and non-zero."); |
| 61 |
} |
| 62 |
|
| 63 |
if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) { |
| 64 |
throw new XMLParseException("Target acceptance probability has to lie in (0, 1)"); |
| 65 |
} |
| 66 |
SubtreeLeapOperator operator = new SubtreeLeapOperator(treeModel, weight, size, targetAcceptance, mode); |
| 67 |
|
| 68 |
return operator; |
| 69 |
} |
| 70 |
|
| 71 |
public String getParserDescription() { |
| 72 |
return "An operator that moves a subtree a certain patristic distance."; |
| 73 |
} |
| 74 |
|
| 75 |
public Class getReturnType() { |
| 76 |
return SubtreeLeapOperator.class; |
| 77 |
} |
| 78 |
|
| 79 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 80 |
return rules; |
| 81 |
} |
| 82 |
|
| 83 |
private final XMLSyntaxRule[] rules = { |
| 84 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 85 |
AttributeRule.newDoubleRule(SIZE, false), |
| 86 |
AttributeRule.newDoubleRule(TARGET_ACCEPTANCE, true), |
| 87 |
AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true), |
| 88 |
new ElementRule(TreeModel.class) |
| 89 |
}; |
| 90 |
|
| 91 |
} |