use of dr.evomodel.coalescent.OldGMRFSkyrideLikelihood in project beast-mcmc by beast-dev.
the class GMRFSkyrideGradientParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
// Parameter parameter = (Parameter) xo.getChild(Parameter.class);
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
OldGMRFSkyrideLikelihood skyrideLikelihood = (OldGMRFSkyrideLikelihood) xo.getChild(OldGMRFSkyrideLikelihood.class);
String wrtParameterCase = (String) xo.getAttribute(WRT_PARAMETER);
GMRFGradient.WrtParameter type = GMRFGradient.WrtParameter.factory(wrtParameterCase);
if (type != null) {
type.getWarning((GMRFMultilocusSkyrideLikelihood) skyrideLikelihood);
return new GMRFGradient((GMRFMultilocusSkyrideLikelihood) skyrideLikelihood, type);
}
// Old behaviour
GMRFSkyrideGradient.WrtParameter wrtParameter = setupWrtParameter(wrtParameterCase);
NodeHeightTransform nodeHeightTransform = (NodeHeightTransform) xo.getChild(NodeHeightTransform.class);
return new GMRFSkyrideGradient(skyrideLikelihood, wrtParameter, tree, nodeHeightTransform);
}
use of dr.evomodel.coalescent.OldGMRFSkyrideLikelihood in project beast-mcmc by beast-dev.
the class NodeHeightTransformParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
XMLObject cxo = xo.getChild(NODEHEIGHT);
Parameter nodeHeightParameter = (Parameter) cxo.getChild(Parameter.class);
Parameter ratioParameter = null;
if (xo.hasChildNamed(RATIO)) {
ratioParameter = (Parameter) xo.getChild(RATIO).getChild(Parameter.class);
}
if (ratioParameter != null) {
if (ratioParameter.getDimension() == 1) {
ratioParameter.setDimension(nodeHeightParameter.getDimension());
}
ratioParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, ratioParameter.getDimension()));
}
Parameter coalescentIntervals = null;
OldGMRFSkyrideLikelihood skyrideLikelihood = null;
if (xo.hasChildNamed(COALESCENT_INTERVAL)) {
cxo = xo.getChild(COALESCENT_INTERVAL);
skyrideLikelihood = (OldGMRFSkyrideLikelihood) cxo.getChild(OldGMRFSkyrideLikelihood.class);
}
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
Transform nodeHeightTransform;
if (ratioParameter != null) {
NodeHeightTransform transform = new NodeHeightTransform(nodeHeightParameter, ratioParameter, tree, branchRateModel);
if (xo.getChild(RATIO).getAttribute(REAL_LINE, false)) {
List<Transform> transforms = new ArrayList<Transform>();
if (nodeHeightParameter.getDimension() != ratioParameter.getDimension()) {
transforms.add(new Transform.LogTransform());
}
for (int i = 0; i < ratioParameter.getDimension(); i++) {
transforms.add(new Transform.LogitTransform());
}
nodeHeightTransform = new Transform.ComposeMultivariable(new Transform.Array(transforms, nodeHeightParameter), transform);
} else {
nodeHeightTransform = transform;
}
} else {
nodeHeightTransform = new NodeHeightTransform(nodeHeightParameter, tree, skyrideLikelihood);
coalescentIntervals = ((NodeHeightTransform) nodeHeightTransform).getParameter();
cxo = xo.getChild(COALESCENT_INTERVAL);
coalescentIntervals.setId(cxo.getId());
cxo.setNativeObject(coalescentIntervals);
}
return nodeHeightTransform;
}
use of dr.evomodel.coalescent.OldGMRFSkyrideLikelihood 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);
}
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;
}
// 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)) {
OldGMRFSkyrideLikelihood gmrfLikelihood = (OldGMRFSkyrideLikelihood) xo.getChild(OldGMRFSkyrideLikelihood.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);
}
}
Aggregations