use of dr.inference.model.TransformedParameter in project beast-mcmc by beast-dev.
the class RandomWalkGammaPrecisionGibbsOperator method main.
public static void main(String[] args) {
Parameter logPop = new Parameter.Default(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0 });
Transform tr = new Transform.LogTransform();
Parameter effPop = new TransformedParameter(logPop, tr, true);
}
use of dr.inference.model.TransformedParameter in project beast-mcmc by beast-dev.
the class TransformedParameterParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final Parameter parameter = (Parameter) xo.getChild(Parameter.class);
final Transform.ParsedTransform parsedTransform = (Transform.ParsedTransform) xo.getChild(Transform.ParsedTransform.class);
final boolean inverse = xo.getAttribute(INVERSE, false);
TransformedParameter transformedParameter = new TransformedParameter(parameter, parsedTransform.transform, inverse);
return transformedParameter;
}
use of dr.inference.model.TransformedParameter 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);
}
}
Aggregations