Search in sources :

Example 1 with OldGMRFSkyrideLikelihood

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);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) GMRFSkyrideGradient(dr.evomodel.coalescent.GMRFSkyrideGradient) NodeHeightTransform(dr.evomodel.treedatalikelihood.discrete.NodeHeightTransform) OldGMRFSkyrideLikelihood(dr.evomodel.coalescent.OldGMRFSkyrideLikelihood) GMRFGradient(dr.evomodel.coalescent.hmc.GMRFGradient)

Example 2 with OldGMRFSkyrideLikelihood

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;
}
Also used : NodeHeightTransform(dr.evomodel.treedatalikelihood.discrete.NodeHeightTransform) OldGMRFSkyrideLikelihood(dr.evomodel.coalescent.OldGMRFSkyrideLikelihood) ArrayList(java.util.ArrayList) TreeModel(dr.evomodel.tree.TreeModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) Parameter(dr.inference.model.Parameter) NodeHeightTransform(dr.evomodel.treedatalikelihood.discrete.NodeHeightTransform) Transform(dr.util.Transform)

Example 3 with OldGMRFSkyrideLikelihood

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);
    }
}
Also used : OldGMRFSkyrideLikelihood(dr.evomodel.coalescent.OldGMRFSkyrideLikelihood) IOException(java.io.IOException) AdaptationMode(dr.inference.operators.AdaptationMode) GMRFSkyrideBlockUpdateOperator(dr.evomodel.coalescent.operators.GMRFSkyrideBlockUpdateOperator) GMRFMultilocusSkyrideLikelihood(dr.evomodel.coalescent.GMRFMultilocusSkyrideLikelihood) GMRFMultilocusSkyrideBlockUpdateOperator(dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator)

Aggregations

OldGMRFSkyrideLikelihood (dr.evomodel.coalescent.OldGMRFSkyrideLikelihood)3 TreeModel (dr.evomodel.tree.TreeModel)2 NodeHeightTransform (dr.evomodel.treedatalikelihood.discrete.NodeHeightTransform)2 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 GMRFMultilocusSkyrideLikelihood (dr.evomodel.coalescent.GMRFMultilocusSkyrideLikelihood)1 GMRFSkyrideGradient (dr.evomodel.coalescent.GMRFSkyrideGradient)1 GMRFGradient (dr.evomodel.coalescent.hmc.GMRFGradient)1 GMRFMultilocusSkyrideBlockUpdateOperator (dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator)1 GMRFSkyrideBlockUpdateOperator (dr.evomodel.coalescent.operators.GMRFSkyrideBlockUpdateOperator)1 Parameter (dr.inference.model.Parameter)1 AdaptationMode (dr.inference.operators.AdaptationMode)1 Transform (dr.util.Transform)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1