Search in sources :

Example 1 with CoercionMode

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

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

Example 2 with CoercionMode

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

the class RandomWalkOperatorParser 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);
    }
    if (lower != null || upper != null) {
        throw new XMLParseException("Do not provide lower/upper bounds on for a RandomWalkOperator; set these values are parameter bounds");
    }
    RandomWalkOperator.BoundaryCondition condition = RandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, RandomWalkOperator.BoundaryCondition.reflecting.name()));
    if (condition == RandomWalkOperator.BoundaryCondition.logit) {
        final Bounds<Double> bounds = parameter.getBounds();
        final int dim = parameter.getDimension();
        boolean boundsSet = true;
        for (int i = 0; i < dim; ++i) {
            if (bounds.getLowerLimit(i) == null || Double.isInfinite(bounds.getLowerLimit(i))) {
                boundsSet = false;
            }
            if (bounds.getUpperLimit(i) == null || Double.isInfinite(bounds.getUpperLimit(i))) {
                boundsSet = false;
            }
        }
        if (!boundsSet) {
            throw new XMLParseException("The logit transformed RandomWalkOperator cannot be used on a parameter without bounds.");
        }
    }
    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 RandomWalkOperator(parameter, updateIndex, windowSize, condition, weight, mode, lower, upper);
    }
    return new RandomWalkOperator(parameter, null, windowSize, condition, weight, mode, lower, upper);
}
Also used : RandomWalkOperator(dr.inference.operators.RandomWalkOperator) Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode)

Example 3 with CoercionMode

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

the class LoadingsIndependenceOperatorParser 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);
    LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
    DistributionLikelihood prior = (DistributionLikelihood) xo.getChild(DistributionLikelihood.class);
    boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
    //To change body of implemented methods use File | Settings | File Templates.
    return new LoadingsIndependenceOperator(LFM, prior, weight, randomScan, scaleFactor, mode);
}
Also used : LoadingsIndependenceOperator(dr.inference.operators.LoadingsIndependenceOperator) LatentFactorModel(dr.inference.model.LatentFactorModel) CoercionMode(dr.inference.operators.CoercionMode) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood)

Example 4 with CoercionMode

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

the class LatentFactorHamiltonianMCParser method parseXMLObject.

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

Example 5 with CoercionMode

use of dr.inference.operators.CoercionMode 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);
    }
    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);
    //                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) GaussianProcessSkytrackLikelihood(dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood) GaussianProcessSkytrackBlockUpdateOperator(dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator) 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