Search in sources :

Example 21 with CoercionMode

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

the class LogRandomWalkOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final double size = xo.getDoubleAttribute(WINDOW_SIZE);
    final boolean scaleAll = xo.getAttribute(SCALE_ALL, false);
    final boolean scaleAllInd = xo.getAttribute(SCALE_ALL_IND, false);
    if (size <= 0.0) {
        throw new XMLParseException("size must be positive");
    }
    final Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    return new LogRandomWalkOperator(parameter, size, mode, weight, scaleAll, scaleAllInd);
}
Also used : LogRandomWalkOperator(dr.inference.operators.LogRandomWalkOperator) Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode)

Example 22 with CoercionMode

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

the class MVOUCovarianceOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double mixingFactor = xo.getDoubleAttribute(MIXING_FACTOR);
    int priorDf = xo.getIntegerAttribute(PRIOR_DF);
    if (mixingFactor <= 0.0 || mixingFactor >= 1.0) {
        throw new XMLParseException("mixingFactor must be greater than 0.0 and less thatn 1.0");
    }
    //            Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    //            XMLObject cxo = (XMLObject) xo.getChild(VARIANCE_MATRIX);
    MatrixParameter varMatrix = (MatrixParameter) xo.getChild(MatrixParameter.class);
    if (varMatrix.getColumnDimension() != varMatrix.getRowDimension())
        throw new XMLParseException("The variance matrix is not square");
    return new MVOUCovarianceOperator(mixingFactor, varMatrix, priorDf, weight, mode);
}
Also used : MVOUCovarianceOperator(dr.inference.operators.MVOUCovarianceOperator) MatrixParameter(dr.inference.model.MatrixParameter) CoercionMode(dr.inference.operators.CoercionMode)

Example 23 with CoercionMode

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

the class ScaleOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final boolean scaleAll = xo.getAttribute(SCALE_ALL, false);
    final boolean scaleAllInd = xo.getAttribute(SCALE_ALL_IND, false);
    final int degreesOfFreedom = xo.getAttribute(DEGREES_OF_FREEDOM, 0);
    final 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 Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    Bounds<Double> bounds = parameter.getBounds();
    for (int dim = 0; dim < parameter.getDimension(); dim++) {
        if (bounds.getLowerLimit(dim) < 0.0) {
            throw new XMLParseException("Scale operator can only be used on parameters with a lower bound of zero (" + parameter.getId() + ")");
        }
        if (!Double.isInfinite(bounds.getUpperLimit(dim))) {
            throw new XMLParseException("Scale operator can't be used on parameters with a finite upper bound (use a RandomWalk) (" + parameter.getId() + ")");
        }
    }
    Parameter indicator = null;
    double indicatorOnProb = 1.0;
    final XMLObject inds = xo.getChild(INDICATORS);
    if (inds != null) {
        indicator = (Parameter) inds.getChild(Parameter.class);
        if (inds.hasAttribute(PICKONEPROB)) {
            indicatorOnProb = inds.getDoubleAttribute(PICKONEPROB);
            if (!(0 <= indicatorOnProb && indicatorOnProb <= 1)) {
                throw new XMLParseException("pickoneprob must be between 0.0 and 1.0");
            }
        }
    }
    ScaleOperator operator = new ScaleOperator(parameter, scaleAll, degreesOfFreedom, scaleFactor, mode, indicator, indicatorOnProb, scaleAllInd);
    operator.setWeight(weight);
    return operator;
}
Also used : Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode) ScaleOperator(dr.inference.operators.ScaleOperator)

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