Search in sources :

Example 1 with TransformedRandomWalkOperator

use of dr.inference.operators.TransformedRandomWalkOperator in project beast-mcmc by beast-dev.

the class TransformedRandomWalkOperatorParser method parseXMLObject.

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);
    int dim = parameter.getDimension();
    Transform[] transformations = new Transform[dim];
    for (int i = 0; i < dim; i++) {
        transformations[i] = Transform.NONE;
    }
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof Transform.ParsedTransform) {
            Transform.ParsedTransform thisObject = (Transform.ParsedTransform) child;
            System.err.println("Transformations:");
            for (int j = thisObject.start; j < thisObject.end; ++j) {
                transformations[j] = thisObject.transform;
                System.err.print(transformations[j].getTransformName() + " ");
            }
            System.err.println();
        }
    }
    Double lower = null;
    Double upper = null;
    if (xo.hasAttribute(LOWER)) {
        lower = xo.getDoubleAttribute(LOWER);
    }
    if (xo.hasAttribute(UPPER)) {
        upper = xo.getDoubleAttribute(UPPER);
    }
    TransformedRandomWalkOperator.BoundaryCondition condition = TransformedRandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, TransformedRandomWalkOperator.BoundaryCondition.reflecting.name()));
    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 TransformedRandomWalkOperator(parameter, transformations, updateIndex, windowSize, condition, weight, mode, lower, upper);
    }
    return new TransformedRandomWalkOperator(parameter, transformations, null, windowSize, condition, weight, mode, lower, upper);
}
Also used : TransformedRandomWalkOperator(dr.inference.operators.TransformedRandomWalkOperator) XMLObject(dr.xml.XMLObject) Parameter(dr.inference.model.Parameter) XMLObject(dr.xml.XMLObject) CoercionMode(dr.inference.operators.CoercionMode) Transform(dr.util.Transform)

Aggregations

Parameter (dr.inference.model.Parameter)1 CoercionMode (dr.inference.operators.CoercionMode)1 TransformedRandomWalkOperator (dr.inference.operators.TransformedRandomWalkOperator)1 Transform (dr.util.Transform)1 XMLObject (dr.xml.XMLObject)1