import dr.inference.model.Parameter; //导入方法依赖的package包/类
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double windowSize = xo.getDoubleAttribute(WINDOW_SIZE);
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
if (xo.hasAttribute(LOWER) || xo.hasAttribute(UPPER)) {
throw new XMLParseException("Do not provide lower/upper bounds on for a RandomWalkOperator; set these values are parameter bounds");
}
RandomWalkOperator.BoundaryCondition condition = RandomWalkOperator.BoundaryCondition.valueOf(
xo.getAttribute(BOUNDARY_CONDITION, RandomWalkOperator.BoundaryCondition.reflecting.name()));
final Bounds bounds = parameter.getBounds();
final int dim = parameter.getDimension();
boolean lowerBoundsSet = true;
boolean upperBoundsSet = true;
for (int i = 0; i < dim; ++i) {
if (bounds.getLowerLimit(i) == null || Double.isInfinite(bounds.getLowerLimit(i))) {
lowerBoundsSet = false;
}
if (bounds.getUpperLimit(i) == null || Double.isInfinite(bounds.getUpperLimit(i))) {
upperBoundsSet = false;
}
}
if (condition == RandomWalkOperator.BoundaryCondition.logit) {
if (!lowerBoundsSet || !upperBoundsSet) {
throw new XMLParseException("The logit transformed RandomWalkOperator cannot be used on a parameter without bounds.");
}
}
if (condition == RandomWalkOperator.BoundaryCondition.log) {
if (!lowerBoundsSet) {
throw new XMLParseException("The log transformed RandomWalkOperator cannot be used on a parameter without lower bounds.");
}
}
if (xo.hasChildNamed(UPDATE_INDEX)) {
XMLObject cxo = xo.getChild(UPDATE_INDEX);
Parameter updateIndex = (Parameter) cxo.getChild(Parameter.class);
if (updateIndex.getDimension() != parameter.getDimension())
throw new RuntimeException("Parameter to update and missing indices must have the same dimension");
return new RandomWalkOperator(parameter, updateIndex, windowSize, condition,
weight, mode);
}
return new RandomWalkOperator(parameter, null, windowSize, condition, weight, mode);
}