use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class DeltaExchangeOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
final boolean isIntegerOperator = xo.getAttribute(INTEGER_OPERATOR, false);
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double delta = xo.getDoubleAttribute(DELTA);
if (delta <= 0.0) {
throw new XMLParseException("delta must be greater than 0.0");
}
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
int[] parameterWeights;
if (xo.hasAttribute(PARAMETER_WEIGHTS)) {
parameterWeights = xo.getIntegerArrayAttribute(PARAMETER_WEIGHTS);
System.out.print("Parameter weights for delta exchange are: ");
for (int parameterWeight : parameterWeights) {
System.out.print(parameterWeight + "\t");
}
System.out.println();
} else {
parameterWeights = new int[parameter.getDimension()];
for (int i = 0; i < parameterWeights.length; i++) {
parameterWeights[i] = 1;
}
}
if (parameterWeights.length != parameter.getDimension()) {
throw new XMLParseException("parameter weights have the same length as parameter");
}
return new DeltaExchangeOperator(parameter, parameterWeights, delta, weight, isIntegerOperator, mode);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class DeltaMixOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double delta = xo.getDoubleAttribute(DELTA);
if (delta <= 0.0 || delta >= 1) {
throw new XMLParseException("delta must be between 0.0 and 1.0");
}
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
int[] parameterWeights;
if (xo.hasAttribute(PARAMETER_WEIGHTS)) {
parameterWeights = xo.getIntegerArrayAttribute(PARAMETER_WEIGHTS);
System.out.print("Parameter weights for delta exchange are: ");
for (int parameterWeight : parameterWeights) {
System.out.print(parameterWeight + "\t");
}
System.out.println();
} else {
parameterWeights = new int[parameter.getDimension()];
for (int i = 0; i < parameterWeights.length; i++) {
parameterWeights[i] = 1;
}
}
if (parameterWeights.length != parameter.getDimension()) {
throw new XMLParseException("parameter weights have the same length as parameter");
}
return new DeltaMixOperator(parameter, parameterWeights, delta, weight, mode);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class GMRFSkyrideBlockUpdateOperatorParser 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.GMRFSkyrideBlockUpdateOperator");
gmrfLogger.setUseParentHandlers(false);
if (logRecord) {
gmrfLogger.setLevel(Level.FINE);
try {
gmrfHandler = new FileHandler("GMRFBlockUpdate.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);
}
CoercionMode mode = CoercionMode.parseMode(xo);
if (mode == CoercionMode.DEFAULT)
mode = CoercionMode.COERCION_ON;
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
if (scaleFactor == 1.0) {
mode = CoercionMode.COERCION_OFF;
}
// 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) && !(xo.getName().compareTo(GRID_BLOCK_UPDATE_OPERATOR) == 0)) {
GMRFSkyrideLikelihood gmrfLikelihood = (GMRFSkyrideLikelihood) xo.getChild(GMRFSkyrideLikelihood.class);
return new GMRFSkyrideBlockUpdateOperator(gmrfLikelihood, weight, mode, scaleFactor, maxIterations, stopValue);
} else {
GMRFMultilocusSkyrideLikelihood gmrfMultilocusLikelihood = (GMRFMultilocusSkyrideLikelihood) xo.getChild(GMRFMultilocusSkyrideLikelihood.class);
return new GMRFMultilocusSkyrideBlockUpdateOperator(gmrfMultilocusLikelihood, weight, mode, scaleFactor, maxIterations, stopValue);
}
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class GaussianProcessSkytrackTreeOperatorParser 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);
// }
CoercionMode mode = CoercionMode.parseMode(xo);
if (mode == CoercionMode.DEFAULT)
mode = CoercionMode.COERCION_ON;
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
// if (scaleFactor <= 0.0) {
// 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);
GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
return new GaussianProcessSkytrackTreeOperator(treeModel, gpLikelihood, weight, scaleFactor, mode);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class FunkyPriorMixerOperatorParser 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);
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
RandomWalkOperator.BoundaryCondition condition = RandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, RandomWalkOperator.BoundaryCondition.reflecting.name()));
return new FunkyPriorMixerOperator(treeModel, parameter, windowSize, condition, weight, mode);
}
Aggregations