| 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.ImportanceSubtreeSwap; |
| 29 |
import dr.evomodel.tree.TreeModel; |
| 30 |
import dr.inference.operators.MCMCOperator; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class ImportanceSubtreeSwapParser extends AbstractXMLObjectParser { |
| 36 |
|
| 37 |
public static final String IMPORTANCE_SUBTREE_SWAP = "ImportanceSubtreeSwap"; |
| 38 |
|
| 39 |
public String getParserName() { |
| 40 |
return IMPORTANCE_SUBTREE_SWAP; |
| 41 |
} |
| 42 |
|
| 43 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 44 |
|
| 45 |
final TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 46 |
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 47 |
final int samples = xo.getIntegerAttribute("samples"); |
| 48 |
|
| 49 |
return new ImportanceSubtreeSwap(treeModel, weight, samples); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public String getParserDescription() { |
| 57 |
return "This element represents a importance guided subtree swap operator. " |
| 58 |
+ "This operator swaps a random subtree with a second subtree guided by an importance distribution."; |
| 59 |
} |
| 60 |
|
| 61 |
public Class getReturnType() { |
| 62 |
return ImportanceSubtreeSwap.class; |
| 63 |
} |
| 64 |
|
| 65 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 66 |
return rules; |
| 67 |
} |
| 68 |
|
| 69 |
private final XMLSyntaxRule[] rules;{ |
| 70 |
rules = new XMLSyntaxRule[]{ |
| 71 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 72 |
AttributeRule.newIntegerRule("samples"), |
| 73 |
new ElementRule(TreeModel.class) |
| 74 |
}; |
| 75 |
} |
| 76 |
|
| 77 |
} |