use of dr.inference.operators.AdaptationMode in project beast-mcmc by beast-dev.
the class ClusterWalkOperatorParser 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);
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.AdaptationMode in project beast-mcmc by beast-dev.
the class CladeAwareSubtreeLeapOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
AdaptationMode mode = AdaptationMode.parseMode(xo);
CladeNodeModel cladeModel = (CladeNodeModel) xo.getChild(CladeNodeModel.class);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final double size = xo.getAttribute(SIZE, Double.NaN);
final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
CladeAwareSubtreeLeap.DistanceKernelType distanceKernel = CladeAwareSubtreeLeap.DistanceKernelType.NORMAL;
if (size <= 0.0) {
throw new XMLParseException("The SubTreeLeap size attribute must be positive and non-zero.");
}
if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) {
throw new XMLParseException("Target acceptance probability has to lie in (0, 1)");
}
final boolean slideOnly = xo.getAttribute(SLIDE_ONLY, false);
return new CladeAwareSubtreeLeap(cladeModel, weight, size, distanceKernel, mode, targetAcceptance, slideOnly);
}
use of dr.inference.operators.AdaptationMode in project beast-mcmc by beast-dev.
the class GaussianProcessSkytrackBlockUpdateOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
boolean logRecord = xo.getAttribute(KEEP_LOG_RECORD, false);
Handler gmrfHandler;
Logger gmrfLogger = Logger.getLogger("dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator");
gmrfLogger.setUseParentHandlers(false);
if (logRecord) {
gmrfLogger.setLevel(Level.FINE);
try {
gmrfHandler = new FileHandler("GPBlockUpdate.log." + MathUtils.getSeed());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
gmrfHandler.setLevel(Level.FINE);
gmrfHandler.setFormatter(new XMLFormatter() {
public String format(LogRecord record) {
return "<record>\n \t<message>\n\t" + record.getMessage() + "\n\t</message>\n<record>\n";
}
});
gmrfLogger.addHandler(gmrfHandler);
}
AdaptationMode mode = AdaptationMode.parseMode(xo);
if (mode == AdaptationMode.DEFAULT)
mode = AdaptationMode.ADAPTATION_ON;
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
// throw new XMLParseException("scaleFactor must be greater than 0.0");
if (scaleFactor < 1.0) {
throw new XMLParseException("scaleFactor must be greater than or equal to 1.0");
}
int maxIterations = xo.getAttribute(MAX_ITERATIONS, 200);
double stopValue = xo.getAttribute(STOP_VALUE, 0.01);
if (xo.getAttribute(OLD_SKYRIDE, true)) {
GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
return new GaussianProcessSkytrackBlockUpdateOperator(gpLikelihood, weight, mode, scaleFactor, maxIterations, stopValue);
} else {
GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
return new GaussianProcessSkytrackBlockUpdateOperator(gpLikelihood, weight, mode, scaleFactor, maxIterations, stopValue);
}
}
use of dr.inference.operators.AdaptationMode in project beast-mcmc by beast-dev.
the class GMRFSkygridBlockUpdateOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
AdaptationMode mode = AdaptationMode.parseMode(xo);
if (mode == AdaptationMode.DEFAULT)
mode = AdaptationMode.ADAPTATION_ON;
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
if (scaleFactor == 1.0) {
mode = AdaptationMode.ADAPTATION_OFF;
}
if (scaleFactor < 1.0) {
throw new XMLParseException("scaleFactor must be greater than or equal to 1.0");
}
int maxIterations = xo.getAttribute(MAX_ITERATIONS, 200);
double stopValue = xo.getAttribute(STOP_VALUE, 0.01);
GMRFSkygridLikelihood gmrfSkygridLikelihood = (GMRFSkygridLikelihood) xo.getChild(GMRFSkygridLikelihood.class);
return new GMRFSkygridBlockUpdateOperator(gmrfSkygridLikelihood, weight, mode, scaleFactor, maxIterations, stopValue);
}
use of dr.inference.operators.AdaptationMode in project beast-mcmc by beast-dev.
the class SubtreeJumpOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
AdaptationMode mode = AdaptationMode.parseMode(xo);
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
// size attribute is mandatory
final double size = xo.getAttribute(SIZE, Double.NaN);
final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
final boolean uniform = xo.getAttribute(UNIFORM, false);
if (size <= 0.0) {
throw new XMLParseException("The SubTreeLeap size attribute must be positive and non-zero.");
}
if (Double.isInfinite(size)) {
// uniform so no auto optimize
mode = AdaptationMode.ADAPTATION_OFF;
}
if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) {
throw new XMLParseException("Target acceptance probability has to lie in (0, 1)");
}
SubtreeJumpOperator operator = new SubtreeJumpOperator(treeModel, weight, size, targetAcceptance, uniform, mode);
return operator;
}
Aggregations