use of dr.evomodel.operators.UniformNodeHeightOperator in project beast-mcmc by beast-dev.
the class NodeHeightOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
OperatorType operatorType = OperatorType.UNIFORM;
if (xo.hasAttribute(OPERATOR_TYPE)) {
try {
operatorType = OperatorType.valueOf(xo.getStringAttribute(OPERATOR_TYPE).trim().toUpperCase());
} catch (IllegalArgumentException iae) {
throw new XMLParseException("Unrecognised operator type attribute: " + xo.getStringAttribute(OPERATOR_TYPE));
}
}
if (operatorType != OperatorType.UNIFORM) {
AdaptationMode mode = AdaptationMode.parseMode(xo);
double tuningParameter = 0.75;
if (xo.hasAttribute(SIZE)) {
tuningParameter = xo.getDoubleAttribute(SIZE);
if (tuningParameter <= 0.0) {
throw new XMLParseException("The UniformNodeHeightOperator size attribute must be positive and non-zero.");
}
}
if (xo.hasAttribute(SCALE_FACTOR)) {
tuningParameter = xo.getDoubleAttribute(SCALE_FACTOR);
if (tuningParameter <= 0.0 || tuningParameter >= 1.0) {
throw new XMLParseException("The UniformNodeHeightOperator scaleFactor attribute must be between 0 and 1.");
}
}
final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) {
throw new XMLParseException("Target acceptance probability has to lie in (0, 1)");
}
switch(operatorType) {
case RANDOMWALK:
return new RandomWalkNodeHeightOperator(treeModel, weight, tuningParameter, mode, targetAcceptance);
case SCALEROOT:
case SCALEALL:
return new ScaleNodeHeightOperator(treeModel, weight, tuningParameter, operatorType, mode, targetAcceptance);
default:
throw new IllegalArgumentException("Unknown operator type");
}
}
if (xo.hasAttribute(SIZE) || xo.hasAttribute(SCALE_FACTOR) || xo.hasAttribute(TARGET_ACCEPTANCE) || xo.hasAttribute(AdaptableMCMCOperator.AUTO_OPTIMIZE)) {
throw new XMLParseException("Uniform node height operator does not take adaptable operator arguments");
}
return new UniformNodeHeightOperator(treeModel, weight);
}
Aggregations