Search in sources :

Example 1 with AdaptationMode

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);
}
Also used : AdaptationMode(dr.inference.operators.AdaptationMode) Parameter(dr.inference.model.Parameter)

Example 2 with AdaptationMode

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);
}
Also used : CladeAwareSubtreeLeap(dr.evomodel.bigfasttree.constrainedtree.CladeAwareSubtreeLeap) AdaptationMode(dr.inference.operators.AdaptationMode) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)

Example 3 with AdaptationMode

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

Example 4 with AdaptationMode

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);
}
Also used : GMRFSkygridBlockUpdateOperator(dr.evomodel.coalescent.operators.GMRFSkygridBlockUpdateOperator) AdaptationMode(dr.inference.operators.AdaptationMode) GMRFSkygridLikelihood(dr.evomodel.coalescent.GMRFSkygridLikelihood)

Example 5 with AdaptationMode

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;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) AdaptationMode(dr.inference.operators.AdaptationMode) SubtreeJumpOperator(dr.evomodel.operators.SubtreeJumpOperator)

Aggregations

AdaptationMode (dr.inference.operators.AdaptationMode)25 TreeModel (dr.evomodel.tree.TreeModel)8 Parameter (dr.inference.model.Parameter)8 LatentFactorModel (dr.inference.model.LatentFactorModel)5 GaussianProcessSkytrackLikelihood (dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood)2 SubtreeLeapOperator (dr.evomodel.operators.SubtreeLeapOperator)2 DiagonalMatrix (dr.inference.model.DiagonalMatrix)2 MatrixParameter (dr.inference.model.MatrixParameter)2 Transform (dr.util.Transform)2 IOException (java.io.IOException)2 NodeRef (dr.evolution.tree.NodeRef)1 Taxa (dr.evolution.util.Taxa)1 Taxon (dr.evolution.util.Taxon)1 CladeAwareSubtreeLeap (dr.evomodel.bigfasttree.constrainedtree.CladeAwareSubtreeLeap)1 CladeNodeModel (dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)1 GMRFMultilocusSkyrideLikelihood (dr.evomodel.coalescent.GMRFMultilocusSkyrideLikelihood)1 GMRFSkygridLikelihood (dr.evomodel.coalescent.GMRFSkygridLikelihood)1 OldGMRFSkyrideLikelihood (dr.evomodel.coalescent.OldGMRFSkyrideLikelihood)1 GMRFMultilocusSkyrideBlockUpdateOperator (dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator)1 GMRFSkygridBlockUpdateOperator (dr.evomodel.coalescent.operators.GMRFSkygridBlockUpdateOperator)1