use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class SubtreeJumpOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.DEFAULT;
if (xo.hasAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
if (xo.getBooleanAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
mode = CoercionMode.COERCION_ON;
} else {
mode = CoercionMode.COERCION_OFF;
}
}
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
// final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
final double bias = xo.getAttribute("bias", 0.0);
final boolean arctanTransform = xo.getAttribute("arctanTransform", true);
if (Double.isInfinite(bias)) {
throw new XMLParseException("bias attribute must be not infinite. was " + bias + " for tree " + treeModel.getId());
}
SubtreeJumpOperator operator = new SubtreeJumpOperator(treeModel, weight, bias, arctanTransform, mode);
return operator;
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class SubtreeSlideOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
boolean swapRates = xo.getAttribute(SWAP_RATES, false);
boolean swapTraits = xo.getAttribute(SWAP_TRAITS, false);
boolean scaledDirichletBranches = xo.getAttribute(DIRICHLET_BRANCHES, false);
CoercionMode mode = CoercionMode.DEFAULT;
if (xo.hasAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
if (xo.getBooleanAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
mode = CoercionMode.COERCION_ON;
} else {
mode = CoercionMode.COERCION_OFF;
}
}
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
final double size = xo.getAttribute("size", 1.0);
if (Double.isInfinite(size) || size <= 0.0) {
throw new XMLParseException("size attribute must be positive and not infinite. was " + size + " for tree " + treeModel.getId());
}
final boolean gaussian = xo.getBooleanAttribute("gaussian");
SubtreeSlideOperator operator = new SubtreeSlideOperator(treeModel, weight, size, gaussian, swapRates, swapTraits, scaledDirichletBranches, mode);
operator.setTargetAcceptanceProbability(targetAcceptance);
return operator;
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class ClusterWalkOperatorParser 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);
Double lower = null;
Double upper = null;
if (xo.hasAttribute(LOWER)) {
lower = xo.getDoubleAttribute(LOWER);
}
if (xo.hasAttribute(UPPER)) {
upper = xo.getDoubleAttribute(UPPER);
}
ClusterWalkOperator.BoundaryCondition condition = ClusterWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, ClusterWalkOperator.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 ClusterWalkOperator(parameter, updateIndex, windowSize, condition, weight, mode, lower, upper);
}
return new ClusterWalkOperator(parameter, null, windowSize, condition, weight, mode, lower, upper);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class LoadingsHamiltonianMCParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
LatentFactorModel lfm = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
MomentDistributionModel prior = (MomentDistributionModel) xo.getChild(MomentDistributionModel.class);
double weight = xo.getDoubleAttribute(WEIGHT);
CoercionMode mode = CoercionMode.parseMode(xo);
int nSteps = xo.getIntegerAttribute(N_STEPS);
double stepSize = xo.getDoubleAttribute(STEP_SIZE);
double momentumSd = xo.getDoubleAttribute(MOMENTUM_SD);
MatrixParameter loadings = (MatrixParameter) xo.getChild(MatrixParameter.class);
return new LoadingsHamiltonianMC(lfm, prior, weight, mode, stepSize, nSteps, momentumSd, loadings);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class FactorIndependenceOperatorParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
String scaleFactorTemp = (String) xo.getAttribute(SCALE_FACTOR);
double scaleFactor = Double.parseDouble(scaleFactorTemp);
String weightTemp = (String) xo.getAttribute(WEIGHT);
double weight = Double.parseDouble(weightTemp);
DiagonalMatrix diffusionMatrix;
diffusionMatrix = (DiagonalMatrix) xo.getChild(DiagonalMatrix.class);
LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
return new FactorIndependenceOperator(LFM, weight, randomScan, diffusionMatrix, scaleFactor, mode);
}
Aggregations