Search in sources :

Example 1 with HamiltonianMonteCarloOperator

use of dr.inference.operators.hmc.HamiltonianMonteCarloOperator 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);
    }
}
Also used : NoUTurnOperator(dr.inference.operators.hmc.NoUTurnOperator) GradientWrtParameterProvider(dr.inference.hmc.GradientWrtParameterProvider) Parameter(dr.inference.model.Parameter) Transform(dr.util.Transform) HamiltonianMonteCarloOperator(dr.inference.operators.hmc.HamiltonianMonteCarloOperator)

Aggregations

GradientWrtParameterProvider (dr.inference.hmc.GradientWrtParameterProvider)1 Parameter (dr.inference.model.Parameter)1 HamiltonianMonteCarloOperator (dr.inference.operators.hmc.HamiltonianMonteCarloOperator)1 NoUTurnOperator (dr.inference.operators.hmc.NoUTurnOperator)1 Transform (dr.util.Transform)1