Search in sources :

Example 1 with TransformedMultivariateParameter

use of dr.inference.model.TransformedMultivariateParameter in project beast-mcmc by beast-dev.

the class RandomWalkOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    AdaptationMode mode = AdaptationMode.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<Double> 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.");
        }
    }
    RandomWalkOperator randomWalk;
    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");
        randomWalk = new RandomWalkOperator(parameter, updateIndex, windowSize, condition, weight, mode);
    } else {
        randomWalk = new RandomWalkOperator(parameter, null, windowSize, condition, weight, mode);
    }
    final Transform transform = parseTransform(xo);
    if (transform == null) {
        return randomWalk;
    } else {
        final boolean inverse = xo.getAttribute(INVERSE, false);
        TransformedParameter transformedParameter;
        if (transform.isMultivariate()) {
            transformedParameter = new TransformedMultivariateParameter(parameter, (Transform.MultivariableTransform) transform, inverse);
        } else {
            transformedParameter = new TransformedParameter(parameter, transform, inverse);
        }
        return new TransformedParameterRandomWalkOperator(transformedParameter, randomWalk);
    }
}
Also used : TransformedMultivariateParameter(dr.inference.model.TransformedMultivariateParameter) TransformedParameter(dr.inference.model.TransformedParameter) TransformedParameter(dr.inference.model.TransformedParameter) Parameter(dr.inference.model.Parameter) TransformedMultivariateParameter(dr.inference.model.TransformedMultivariateParameter) Transform(dr.util.Transform) Util.parseTransform(dr.util.Transform.Util.parseTransform)

Example 2 with TransformedMultivariateParameter

use of dr.inference.model.TransformedMultivariateParameter in project beast-mcmc by beast-dev.

the class TransformedMultivariateParameterParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    Transform.MultivariableTransform transform = (Transform.MultivariableTransform) xo.getChild(Transform.MultivariableTransform.class);
    final boolean inverse = xo.getAttribute(INVERSE, false);
    TransformedMultivariateParameter transformedParameter = new TransformedMultivariateParameter(parameter, transform, inverse);
    if (xo.hasChildNamed(BOUNDS)) {
        Bounds<Double> bounds = ((Parameter) xo.getElementFirstChild(BOUNDS)).getBounds();
        transformedParameter.addBounds(bounds);
    } else {
        transformedParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, parameter.getDimension()));
    }
    return transformedParameter;
}
Also used : TransformedMultivariateParameter(dr.inference.model.TransformedMultivariateParameter) Parameter(dr.inference.model.Parameter) TransformedMultivariateParameter(dr.inference.model.TransformedMultivariateParameter) Transform(dr.util.Transform)

Aggregations

Parameter (dr.inference.model.Parameter)2 TransformedMultivariateParameter (dr.inference.model.TransformedMultivariateParameter)2 Transform (dr.util.Transform)2 TransformedParameter (dr.inference.model.TransformedParameter)1 Util.parseTransform (dr.util.Transform.Util.parseTransform)1