Search in sources :

Example 6 with CoercionMode

use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.

the class SubtreeJumpOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.DEFAULT;
    if (xo.hasAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
        if (xo.getBooleanAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
            mode = CoercionMode.COERCION_ON;
        } else {
            mode = CoercionMode.COERCION_OFF;
        }
    }
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    //        final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
    final double bias = xo.getAttribute("bias", 0.0);
    final boolean arctanTransform = xo.getAttribute("arctanTransform", true);
    if (Double.isInfinite(bias)) {
        throw new XMLParseException("bias attribute must be not infinite. was " + bias + " for tree " + treeModel.getId());
    }
    SubtreeJumpOperator operator = new SubtreeJumpOperator(treeModel, weight, bias, arctanTransform, mode);
    return operator;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) SubtreeJumpOperator(dr.evomodel.operators.SubtreeJumpOperator) CoercionMode(dr.inference.operators.CoercionMode)

Example 7 with CoercionMode

use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.

the class SubtreeSlideOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    boolean swapRates = xo.getAttribute(SWAP_RATES, false);
    boolean swapTraits = xo.getAttribute(SWAP_TRAITS, false);
    boolean scaledDirichletBranches = xo.getAttribute(DIRICHLET_BRANCHES, false);
    CoercionMode mode = CoercionMode.DEFAULT;
    if (xo.hasAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
        if (xo.getBooleanAttribute(CoercableMCMCOperator.AUTO_OPTIMIZE)) {
            mode = CoercionMode.COERCION_ON;
        } else {
            mode = CoercionMode.COERCION_OFF;
        }
    }
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
    final double size = xo.getAttribute("size", 1.0);
    if (Double.isInfinite(size) || size <= 0.0) {
        throw new XMLParseException("size attribute must be positive and not infinite. was " + size + " for tree " + treeModel.getId());
    }
    final boolean gaussian = xo.getBooleanAttribute("gaussian");
    SubtreeSlideOperator operator = new SubtreeSlideOperator(treeModel, weight, size, gaussian, swapRates, swapTraits, scaledDirichletBranches, mode);
    operator.setTargetAcceptanceProbability(targetAcceptance);
    return operator;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) SubtreeSlideOperator(dr.evomodel.operators.SubtreeSlideOperator) CoercionMode(dr.inference.operators.CoercionMode)

Example 8 with CoercionMode

use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.

the class ClusterWalkOperatorParser 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);
    }
    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 : Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode)

Example 9 with CoercionMode

use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.

the class LoadingsHamiltonianMCParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    LatentFactorModel lfm = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
    MomentDistributionModel prior = (MomentDistributionModel) xo.getChild(MomentDistributionModel.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);
    MatrixParameter loadings = (MatrixParameter) xo.getChild(MatrixParameter.class);
    return new LoadingsHamiltonianMC(lfm, prior, weight, mode, stepSize, nSteps, momentumSd, loadings);
}
Also used : MatrixParameter(dr.inference.model.MatrixParameter) LoadingsHamiltonianMC(dr.inference.operators.hmc.deprecated.LoadingsHamiltonianMC) LatentFactorModel(dr.inference.model.LatentFactorModel) MomentDistributionModel(dr.inference.distribution.MomentDistributionModel) CoercionMode(dr.inference.operators.CoercionMode)

Example 10 with CoercionMode

use of dr.inference.operators.CoercionMode in project beast-mcmc by beast-dev.

the class FactorIndependenceOperatorParser 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 FactorIndependenceOperator(LFM, weight, randomScan, diffusionMatrix, scaleFactor, mode);
}
Also used : DiagonalMatrix(dr.inference.model.DiagonalMatrix) FactorIndependenceOperator(dr.inference.operators.FactorIndependenceOperator) LatentFactorModel(dr.inference.model.LatentFactorModel) CoercionMode(dr.inference.operators.CoercionMode)

Aggregations

CoercionMode (dr.inference.operators.CoercionMode)23 Parameter (dr.inference.model.Parameter)10 TreeModel (dr.evomodel.tree.TreeModel)7 LatentFactorModel (dr.inference.model.LatentFactorModel)5 GaussianProcessSkytrackLikelihood (dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood)2 DiagonalMatrix (dr.inference.model.DiagonalMatrix)2 MatrixParameter (dr.inference.model.MatrixParameter)2 RandomWalkOperator (dr.inference.operators.RandomWalkOperator)2 IOException (java.io.IOException)2 GMRFMultilocusSkyrideLikelihood (dr.evomodel.coalescent.GMRFMultilocusSkyrideLikelihood)1 GMRFSkyrideLikelihood (dr.evomodel.coalescent.GMRFSkyrideLikelihood)1 GMRFMultilocusSkyrideBlockUpdateOperator (dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator)1 GMRFSkyrideBlockUpdateOperator (dr.evomodel.coalescent.operators.GMRFSkyrideBlockUpdateOperator)1 GaussianProcessSkytrackBlockUpdateOperator (dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator)1 GaussianProcessSkytrackTreeOperator (dr.evomodel.coalescent.operators.GaussianProcessSkytrackTreeOperator)1 FullyConjugateMultivariateTraitLikelihood (dr.evomodel.continuous.FullyConjugateMultivariateTraitLikelihood)1 FunkyPriorMixerOperator (dr.evomodel.operators.FunkyPriorMixerOperator)1 RateScaleOperator (dr.evomodel.operators.RateScaleOperator)1 RateVarianceScaleOperator (dr.evomodel.operators.RateVarianceScaleOperator)1 SubtreeJumpOperator (dr.evomodel.operators.SubtreeJumpOperator)1