use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class FactorOperatorParser 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 FactorOperator(LFM, weight, randomScan, diffusionMatrix, scaleFactor, mode);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class RandomWalkOperatorParser 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);
}
if (lower != null || upper != null) {
throw new XMLParseException("Do not provide lower/upper bounds on for a RandomWalkOperator; set these values are parameter bounds");
}
RandomWalkOperator.BoundaryCondition condition = RandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, RandomWalkOperator.BoundaryCondition.reflecting.name()));
if (condition == RandomWalkOperator.BoundaryCondition.logit) {
final Bounds<Double> bounds = parameter.getBounds();
final int dim = parameter.getDimension();
boolean boundsSet = true;
for (int i = 0; i < dim; ++i) {
if (bounds.getLowerLimit(i) == null || Double.isInfinite(bounds.getLowerLimit(i))) {
boundsSet = false;
}
if (bounds.getUpperLimit(i) == null || Double.isInfinite(bounds.getUpperLimit(i))) {
boundsSet = false;
}
}
if (!boundsSet) {
throw new XMLParseException("The logit transformed RandomWalkOperator cannot be used on a parameter without bounds.");
}
}
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 RandomWalkOperator(parameter, updateIndex, windowSize, condition, weight, mode, lower, upper);
}
return new RandomWalkOperator(parameter, null, windowSize, condition, weight, mode, lower, upper);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class LoadingsIndependenceOperatorParser 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);
LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
DistributionLikelihood prior = (DistributionLikelihood) xo.getChild(DistributionLikelihood.class);
boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
//To change body of implemented methods use File | Settings | File Templates.
return new LoadingsIndependenceOperator(LFM, prior, weight, randomScan, scaleFactor, mode);
}
use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.
the class LatentFactorHamiltonianMCParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
LatentFactorModel lfm = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
FullyConjugateMultivariateTraitLikelihood tree = (FullyConjugateMultivariateTraitLikelihood) xo.getChild(FullyConjugateMultivariateTraitLikelihood.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);
return new LatentFactorHamiltonianMC(lfm, tree, weight, mode, stepSize, nSteps, momentumSd);
}
use of dr.inference.operators.CoercionMode 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);
}
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);
// 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);
}
}
Aggregations