Search in sources :

Example 11 with CoercionMode

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

the class DeltaExchangeOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    final boolean isIntegerOperator = xo.getAttribute(INTEGER_OPERATOR, false);
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double delta = xo.getDoubleAttribute(DELTA);
    if (delta <= 0.0) {
        throw new XMLParseException("delta must be greater than 0.0");
    }
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    int[] parameterWeights;
    if (xo.hasAttribute(PARAMETER_WEIGHTS)) {
        parameterWeights = xo.getIntegerArrayAttribute(PARAMETER_WEIGHTS);
        System.out.print("Parameter weights for delta exchange are: ");
        for (int parameterWeight : parameterWeights) {
            System.out.print(parameterWeight + "\t");
        }
        System.out.println();
    } else {
        parameterWeights = new int[parameter.getDimension()];
        for (int i = 0; i < parameterWeights.length; i++) {
            parameterWeights[i] = 1;
        }
    }
    if (parameterWeights.length != parameter.getDimension()) {
        throw new XMLParseException("parameter weights have the same length as parameter");
    }
    return new DeltaExchangeOperator(parameter, parameterWeights, delta, weight, isIntegerOperator, mode);
}
Also used : Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode) DeltaExchangeOperator(dr.inference.operators.DeltaExchangeOperator)

Example 12 with CoercionMode

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

the class DeltaMixOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double delta = xo.getDoubleAttribute(DELTA);
    if (delta <= 0.0 || delta >= 1) {
        throw new XMLParseException("delta must be between 0.0 and 1.0");
    }
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    int[] parameterWeights;
    if (xo.hasAttribute(PARAMETER_WEIGHTS)) {
        parameterWeights = xo.getIntegerArrayAttribute(PARAMETER_WEIGHTS);
        System.out.print("Parameter weights for delta exchange are: ");
        for (int parameterWeight : parameterWeights) {
            System.out.print(parameterWeight + "\t");
        }
        System.out.println();
    } else {
        parameterWeights = new int[parameter.getDimension()];
        for (int i = 0; i < parameterWeights.length; i++) {
            parameterWeights[i] = 1;
        }
    }
    if (parameterWeights.length != parameter.getDimension()) {
        throw new XMLParseException("parameter weights have the same length as parameter");
    }
    return new DeltaMixOperator(parameter, parameterWeights, delta, weight, mode);
}
Also used : Parameter(dr.inference.model.Parameter) DeltaMixOperator(dr.inference.operators.DeltaMixOperator) CoercionMode(dr.inference.operators.CoercionMode)

Example 13 with CoercionMode

use of dr.inference.operators.CoercionMode 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);
    }
    CoercionMode mode = CoercionMode.parseMode(xo);
    if (mode == CoercionMode.DEFAULT)
        mode = CoercionMode.COERCION_ON;
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
    if (scaleFactor == 1.0) {
        mode = CoercionMode.COERCION_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)) {
        GMRFSkyrideLikelihood gmrfLikelihood = (GMRFSkyrideLikelihood) xo.getChild(GMRFSkyrideLikelihood.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 : GMRFSkyrideLikelihood(dr.evomodel.coalescent.GMRFSkyrideLikelihood) IOException(java.io.IOException) GMRFSkyrideBlockUpdateOperator(dr.evomodel.coalescent.operators.GMRFSkyrideBlockUpdateOperator) CoercionMode(dr.inference.operators.CoercionMode) GMRFMultilocusSkyrideLikelihood(dr.evomodel.coalescent.GMRFMultilocusSkyrideLikelihood) GMRFMultilocusSkyrideBlockUpdateOperator(dr.evomodel.coalescent.operators.GMRFMultilocusSkyrideBlockUpdateOperator)

Example 14 with CoercionMode

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

the class GaussianProcessSkytrackTreeOperatorParser 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);
    //        }
    CoercionMode mode = CoercionMode.parseMode(xo);
    if (mode == CoercionMode.DEFAULT)
        mode = CoercionMode.COERCION_ON;
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
    //            if (scaleFactor <= 0.0) {
    //                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);
    GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    return new GaussianProcessSkytrackTreeOperator(treeModel, gpLikelihood, weight, scaleFactor, mode);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) GaussianProcessSkytrackTreeOperator(dr.evomodel.coalescent.operators.GaussianProcessSkytrackTreeOperator) GaussianProcessSkytrackLikelihood(dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood) CoercionMode(dr.inference.operators.CoercionMode)

Example 15 with CoercionMode

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

the class FunkyPriorMixerOperatorParser 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);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    RandomWalkOperator.BoundaryCondition condition = RandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, RandomWalkOperator.BoundaryCondition.reflecting.name()));
    return new FunkyPriorMixerOperator(treeModel, parameter, windowSize, condition, weight, mode);
}
Also used : RandomWalkOperator(dr.inference.operators.RandomWalkOperator) TreeModel(dr.evomodel.tree.TreeModel) Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode) FunkyPriorMixerOperator(dr.evomodel.operators.FunkyPriorMixerOperator)

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