Search in sources :

Example 16 with CoercionMode

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

the class RateScaleOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
    final boolean noRoot = xo.getBooleanAttribute(NO_ROOT);
    if (scaleFactor <= 0.0 || scaleFactor >= 1.0) {
        throw new XMLParseException("scaleFactor must be between 0.0 and 1.0");
    }
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    RateScaleOperator operator = new RateScaleOperator(treeModel, scaleFactor, noRoot, mode);
    operator.setWeight(weight);
    return operator;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) CoercionMode(dr.inference.operators.CoercionMode) RateScaleOperator(dr.evomodel.operators.RateScaleOperator)

Example 17 with CoercionMode

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

the class RateVarianceScaleOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
    if (scaleFactor <= 0.0 || scaleFactor >= 1.0) {
        throw new XMLParseException("scaleFactor must be between 0.0 and 1.0");
    }
    final TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    final Parameter variance = (Parameter) xo.getChild(Parameter.class);
    if (variance.getDimension() != 1) {
        throw new XMLParseException("dimension of the variance parameter should be 1");
    }
    RateVarianceScaleOperator operator = new RateVarianceScaleOperator(treeModel, variance, scaleFactor, mode);
    operator.setWeight(weight);
    return operator;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode) RateVarianceScaleOperator(dr.evomodel.operators.RateVarianceScaleOperator)

Example 18 with CoercionMode

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

the class SubtreeLeapOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final double size = xo.getAttribute("size", 1.0);
    final double prob = xo.getAttribute("accP", 0.234);
    if (Double.isInfinite(size) || size <= 0.0) {
        throw new XMLParseException("size attribute must be positive and not infinite. was " + size);
    }
    if (prob <= 0.0 || prob >= 1.0) {
        throw new XMLParseException("Target acceptance probability has to lie in (0, 1). Currently: " + prob);
    }
    SubtreeLeapOperator operator = new SubtreeLeapOperator(treeModel, weight, size, prob, mode);
    return operator;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) CoercionMode(dr.inference.operators.CoercionMode) SubtreeLeapOperator(dr.evomodel.operators.SubtreeLeapOperator)

Example 19 with CoercionMode

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

the class TransformedRandomWalkOperatorParser 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);
    int dim = parameter.getDimension();
    Transform[] transformations = new Transform[dim];
    for (int i = 0; i < dim; i++) {
        transformations[i] = Transform.NONE;
    }
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof Transform.ParsedTransform) {
            Transform.ParsedTransform thisObject = (Transform.ParsedTransform) child;
            System.err.println("Transformations:");
            for (int j = thisObject.start; j < thisObject.end; ++j) {
                transformations[j] = thisObject.transform;
                System.err.print(transformations[j].getTransformName() + " ");
            }
            System.err.println();
        }
    }
    Double lower = null;
    Double upper = null;
    if (xo.hasAttribute(LOWER)) {
        lower = xo.getDoubleAttribute(LOWER);
    }
    if (xo.hasAttribute(UPPER)) {
        upper = xo.getDoubleAttribute(UPPER);
    }
    TransformedRandomWalkOperator.BoundaryCondition condition = TransformedRandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, TransformedRandomWalkOperator.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 TransformedRandomWalkOperator(parameter, transformations, updateIndex, windowSize, condition, weight, mode, lower, upper);
    }
    return new TransformedRandomWalkOperator(parameter, transformations, null, windowSize, condition, weight, mode, lower, upper);
}
Also used : TransformedRandomWalkOperator(dr.inference.operators.TransformedRandomWalkOperator) XMLObject(dr.xml.XMLObject) Parameter(dr.inference.model.Parameter) XMLObject(dr.xml.XMLObject) CoercionMode(dr.inference.operators.CoercionMode) Transform(dr.util.Transform)

Example 20 with CoercionMode

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

the class TwoPhaseOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    if (DEBUG) {
        System.err.println("\nParsing TwoPhaseOperator");
    }
    final CoercionMode mode = CoercionMode.parseMode(xo);
    final double weight = xo.getDoubleAttribute(WEIGHT);
    final int initial = xo.getIntegerAttribute(INITIAL);
    final int burnin = xo.getIntegerAttribute(BURNIN);
    if (DEBUG) {
        System.err.println("child count: " + xo.getChildCount());
        System.err.println(xo.getChild(PHASE_ONE));
        System.err.println(xo.getChild(PHASE_ONE).getChildCount());
        System.err.println(xo.getChild(PHASE_TWO));
        System.err.println(xo.getChild(PHASE_TWO).getChildCount());
    }
    List<AbstractCoercableOperator> phaseOneOperators = new ArrayList<AbstractCoercableOperator>();
    int phaseOneCount = xo.getChild(PHASE_ONE).getChildCount();
    for (int i = 0; i < phaseOneCount; i++) {
        phaseOneOperators.add((AbstractCoercableOperator) xo.getChild(PHASE_ONE).getChild(i));
    }
    if (DEBUG) {
        System.err.println("arrayList one size: " + phaseOneOperators.size());
        for (int i = 0; i < phaseOneOperators.size(); i++) {
            System.err.println("  " + phaseOneOperators.get(i));
        }
    }
    /*List<AbstractCoercableOperator> phaseTwoOperators = new ArrayList<AbstractCoercableOperator>();
        int phaseTwoCount = xo.getChild(PHASE_TWO).getChildCount();
        for (int i = 0; i < phaseTwoCount; i++) {
            phaseTwoOperators.add((AbstractCoercableOperator)xo.getChild(PHASE_TWO).getChild(i));
        }*/
    List<AdaptableVarianceMultivariateNormalOperator> phaseTwoOperators = new ArrayList<AdaptableVarianceMultivariateNormalOperator>();
    int phaseTwoCount = xo.getChild(PHASE_TWO).getChildCount();
    for (int i = 0; i < phaseTwoCount; i++) {
        phaseTwoOperators.add((AdaptableVarianceMultivariateNormalOperator) xo.getChild(PHASE_TWO).getChild(i));
    }
    if (DEBUG) {
        System.err.println("arrayList two size: " + phaseTwoOperators.size());
        for (int i = 0; i < phaseTwoOperators.size(); i++) {
            System.err.println("  " + phaseTwoOperators.get(i));
        }
    }
    //keep track of the parameters of phase one here, as apparently we can't get to them afterwards
    //let's just get them from phase two, as there I can implement whatever I want
    List<Parameter> parameters = new ArrayList<Parameter>();
    for (int i = 0; i < phaseTwoCount; i++) {
        parameters.add(phaseTwoOperators.get(i).getParameter());
    }
    if (DEBUG) {
        System.err.println("parameter list size: " + parameters.size());
        for (int i = 0; i < parameters.size(); i++) {
            System.err.println("  " + parameters.get(i));
        }
    }
    return new TwoPhaseOperator(phaseOneOperators, phaseTwoOperators, parameters, initial, burnin, weight, mode);
}
Also used : ArrayList(java.util.ArrayList) Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode) AbstractCoercableOperator(dr.inference.operators.AbstractCoercableOperator) AdaptableVarianceMultivariateNormalOperator(dr.inference.operators.AdaptableVarianceMultivariateNormalOperator) TwoPhaseOperator(dr.inference.operators.TwoPhaseOperator)

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