use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class RateScaleOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
final boolean noRoot = xo.getBooleanAttribute(NO_ROOT);
if (scaleFactor <= 0.0 || scaleFactor >= 1.0) {
throw new XMLParseException("scaleFactor must be between 0.0 and 1.0");
}
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
RateScaleOperator operator = new RateScaleOperator(treeModel, scaleFactor, noRoot, mode);
operator.setWeight(weight);
return operator;
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class RateVarianceScaleOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
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 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
final Parameter variance = (Parameter) xo.getChild(Parameter.class);
if (variance.getDimension() != 1) {
throw new XMLParseException("dimension of the variance parameter should be 1");
}
RateVarianceScaleOperator operator = new RateVarianceScaleOperator(treeModel, variance, scaleFactor, mode);
operator.setWeight(weight);
return operator;
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class SubtreeLeapOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final double size = xo.getAttribute("size", 1.0);
final double prob = xo.getAttribute("accP", 0.234);
if (Double.isInfinite(size) || size <= 0.0) {
throw new XMLParseException("size attribute must be positive and not infinite. was " + size);
}
if (prob <= 0.0 || prob >= 1.0) {
throw new XMLParseException("Target acceptance probability has to lie in (0, 1). Currently: " + prob);
}
SubtreeLeapOperator operator = new SubtreeLeapOperator(treeModel, weight, size, prob, mode);
return operator;
}
use of dr.inference.operators.CoercionMode 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);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class TwoPhaseOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
if (DEBUG) {
System.err.println("\nParsing TwoPhaseOperator");
}
final CoercionMode mode = CoercionMode.parseMode(xo);
final double weight = xo.getDoubleAttribute(WEIGHT);
final int initial = xo.getIntegerAttribute(INITIAL);
final int burnin = xo.getIntegerAttribute(BURNIN);
if (DEBUG) {
System.err.println("child count: " + xo.getChildCount());
System.err.println(xo.getChild(PHASE_ONE));
System.err.println(xo.getChild(PHASE_ONE).getChildCount());
System.err.println(xo.getChild(PHASE_TWO));
System.err.println(xo.getChild(PHASE_TWO).getChildCount());
}
List<AbstractCoercableOperator> phaseOneOperators = new ArrayList<AbstractCoercableOperator>();
int phaseOneCount = xo.getChild(PHASE_ONE).getChildCount();
for (int i = 0; i < phaseOneCount; i++) {
phaseOneOperators.add((AbstractCoercableOperator) xo.getChild(PHASE_ONE).getChild(i));
}
if (DEBUG) {
System.err.println("arrayList one size: " + phaseOneOperators.size());
for (int i = 0; i < phaseOneOperators.size(); i++) {
System.err.println(" " + phaseOneOperators.get(i));
}
}
/*List<AbstractCoercableOperator> phaseTwoOperators = new ArrayList<AbstractCoercableOperator>();
int phaseTwoCount = xo.getChild(PHASE_TWO).getChildCount();
for (int i = 0; i < phaseTwoCount; i++) {
phaseTwoOperators.add((AbstractCoercableOperator)xo.getChild(PHASE_TWO).getChild(i));
}*/
List<AdaptableVarianceMultivariateNormalOperator> phaseTwoOperators = new ArrayList<AdaptableVarianceMultivariateNormalOperator>();
int phaseTwoCount = xo.getChild(PHASE_TWO).getChildCount();
for (int i = 0; i < phaseTwoCount; i++) {
phaseTwoOperators.add((AdaptableVarianceMultivariateNormalOperator) xo.getChild(PHASE_TWO).getChild(i));
}
if (DEBUG) {
System.err.println("arrayList two size: " + phaseTwoOperators.size());
for (int i = 0; i < phaseTwoOperators.size(); i++) {
System.err.println(" " + phaseTwoOperators.get(i));
}
}
//keep track of the parameters of phase one here, as apparently we can't get to them afterwards
//let's just get them from phase two, as there I can implement whatever I want
List<Parameter> parameters = new ArrayList<Parameter>();
for (int i = 0; i < phaseTwoCount; i++) {
parameters.add(phaseTwoOperators.get(i).getParameter());
}
if (DEBUG) {
System.err.println("parameter list size: " + parameters.size());
for (int i = 0; i < parameters.size(); i++) {
System.err.println(" " + parameters.get(i));
}
}
return new TwoPhaseOperator(phaseOneOperators, phaseTwoOperators, parameters, initial, burnin, weight, mode);
}
Aggregations