use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class LogRandomWalkOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final double size = xo.getDoubleAttribute(WINDOW_SIZE);
final boolean scaleAll = xo.getAttribute(SCALE_ALL, false);
final boolean scaleAllInd = xo.getAttribute(SCALE_ALL_IND, false);
if (size <= 0.0) {
throw new XMLParseException("size must be positive");
}
final Parameter parameter = (Parameter) xo.getChild(Parameter.class);
return new LogRandomWalkOperator(parameter, size, mode, weight, scaleAll, scaleAllInd);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class MVOUCovarianceOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double mixingFactor = xo.getDoubleAttribute(MIXING_FACTOR);
int priorDf = xo.getIntegerAttribute(PRIOR_DF);
if (mixingFactor <= 0.0 || mixingFactor >= 1.0) {
throw new XMLParseException("mixingFactor must be greater than 0.0 and less thatn 1.0");
}
// Parameter parameter = (Parameter) xo.getChild(Parameter.class);
// XMLObject cxo = (XMLObject) xo.getChild(VARIANCE_MATRIX);
MatrixParameter varMatrix = (MatrixParameter) xo.getChild(MatrixParameter.class);
if (varMatrix.getColumnDimension() != varMatrix.getRowDimension())
throw new XMLParseException("The variance matrix is not square");
return new MVOUCovarianceOperator(mixingFactor, varMatrix, priorDf, weight, mode);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class ScaleOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final boolean scaleAll = xo.getAttribute(SCALE_ALL, false);
final boolean scaleAllInd = xo.getAttribute(SCALE_ALL_IND, false);
final int degreesOfFreedom = xo.getAttribute(DEGREES_OF_FREEDOM, 0);
final CoercionMode mode = CoercionMode.parseMode(xo);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
if (scaleFactor <= 0.0 || scaleFactor >= 1.0) {
throw new XMLParseException("scaleFactor must be between 0.0 and 1.0");
}
final Parameter parameter = (Parameter) xo.getChild(Parameter.class);
Bounds<Double> bounds = parameter.getBounds();
for (int dim = 0; dim < parameter.getDimension(); dim++) {
if (bounds.getLowerLimit(dim) < 0.0) {
throw new XMLParseException("Scale operator can only be used on parameters with a lower bound of zero (" + parameter.getId() + ")");
}
if (!Double.isInfinite(bounds.getUpperLimit(dim))) {
throw new XMLParseException("Scale operator can't be used on parameters with a finite upper bound (use a RandomWalk) (" + parameter.getId() + ")");
}
}
Parameter indicator = null;
double indicatorOnProb = 1.0;
final XMLObject inds = xo.getChild(INDICATORS);
if (inds != null) {
indicator = (Parameter) inds.getChild(Parameter.class);
if (inds.hasAttribute(PICKONEPROB)) {
indicatorOnProb = inds.getDoubleAttribute(PICKONEPROB);
if (!(0 <= indicatorOnProb && indicatorOnProb <= 1)) {
throw new XMLParseException("pickoneprob must be between 0.0 and 1.0");
}
}
}
ScaleOperator operator = new ScaleOperator(parameter, scaleAll, degreesOfFreedom, scaleFactor, mode, indicator, indicatorOnProb, scaleAllInd);
operator.setWeight(weight);
return operator;
}
Aggregations