use of dr.inference.operators.hmc.NoUTurnOperator in project beast-mcmc by beast-dev.
the class HamiltonianMonteCarloOperatorParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
int nSteps = xo.getIntegerAttribute(N_STEPS);
double stepSize = xo.getDoubleAttribute(STEP_SIZE);
double drawVariance = xo.getDoubleAttribute(DRAW_VARIANCE);
int mode = xo.getAttribute(MODE, 0);
GradientWrtParameterProvider derivative = (GradientWrtParameterProvider) xo.getChild(GradientWrtParameterProvider.class);
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
Transform transform = null;
if (parameter == null) {
Transform.Collection collection = (Transform.Collection) xo.getChild(Transform.Collection.class);
parameter = collection.getParameter();
transform = collection;
}
if (derivative.getDimension() != parameter.getDimension()) {
throw new XMLParseException("Gradient (" + derivative.getDimension() + ") must be the same dimensions as the parameter (" + parameter.getDimension() + ")");
}
if (mode == 0) {
return new HamiltonianMonteCarloOperator(CoercionMode.DEFAULT, weight, derivative, parameter, transform, stepSize, nSteps, drawVariance);
} else {
return new NoUTurnOperator(CoercionMode.DEFAULT, weight, derivative, parameter, stepSize, nSteps, drawVariance);
}
}
Aggregations