Search in sources :

Example 46 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class NegationOperatorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter data = (Parameter) xo.getChild(Parameter.class);
    double weight = xo.getDoubleAttribute(WEIGHT);
    return new NegationOperator(data, weight);
}
Also used : Parameter(dr.inference.model.Parameter) NegationOperator(dr.inference.operators.NegationOperator)

Example 47 with Parameter

use of dr.inference.model.Parameter 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 48 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class EllipticalSliceOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final Parameter variable = (Parameter) xo.getChild(Parameter.class);
    boolean drawByRowTemp = false;
    if (xo.hasAttribute(DRAW_BY_ROW))
        drawByRowTemp = xo.getBooleanAttribute(DRAW_BY_ROW);
    final boolean drawByRow = drawByRowTemp;
    boolean signal = xo.getAttribute(SIGNAL_CONSTITUENT_PARAMETERS, true);
    if (!signal && !(variable instanceof CompoundParameter))
        signal = true;
    double bracketAngle = xo.getAttribute(BRACKET_ANGLE, 0.0);
    boolean translationInvariant = xo.getAttribute(TRANSLATION_INVARIANT, false);
    boolean rotationInvariant = xo.getAttribute(ROTATION_INVARIANT, false);
    GaussianProcessRandomGenerator gaussianProcess = (GaussianProcessRandomGenerator) xo.getChild(GaussianProcessRandomGenerator.class);
    if (gaussianProcess == null) {
        final MultivariateDistributionLikelihood likelihood = (MultivariateDistributionLikelihood) xo.getChild(MultivariateDistributionLikelihood.class);
        if (!(likelihood.getDistribution() instanceof GaussianProcessRandomGenerator)) {
            throw new XMLParseException("Elliptical slice sampling only works for multivariate normally distributed random variables");
        }
        if (likelihood.getDistribution() instanceof MultivariateNormalDistribution)
            gaussianProcess = (MultivariateNormalDistribution) likelihood.getDistribution();
        if (likelihood.getDistribution() instanceof MultivariateNormalDistributionModel)
            gaussianProcess = (MultivariateNormalDistributionModel) likelihood.getDistribution();
    }
    EllipticalSliceOperator operator = new EllipticalSliceOperator(variable, gaussianProcess, drawByRow, signal, bracketAngle, translationInvariant, rotationInvariant);
    operator.setWeight(weight);
    return operator;
}
Also used : CompoundParameter(dr.inference.model.CompoundParameter) GaussianProcessRandomGenerator(dr.math.distributions.GaussianProcessRandomGenerator) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) MultivariateNormalDistributionModel(dr.inference.distribution.MultivariateNormalDistributionModel) CompoundParameter(dr.inference.model.CompoundParameter) Parameter(dr.inference.model.Parameter) EllipticalSliceOperator(dr.inference.operators.EllipticalSliceOperator) MultivariateNormalDistribution(dr.math.distributions.MultivariateNormalDistribution)

Example 49 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class SwapOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    double weight = xo.getDoubleAttribute("weight");
    int size = xo.getIntegerAttribute("size");
    boolean autoOptimize = xo.getBooleanAttribute("autoOptimize");
    if (autoOptimize)
        throw new XMLParseException("swapOperator can't be optimized!");
    System.out.println("Creating swap operator for parameter " + parameter.getParameterName() + " (weight=" + weight + ")");
    SwapOperator so = new SwapOperator(parameter, size);
    so.setWeight(weight);
    return so;
}
Also used : SwapOperator(dr.inference.operators.SwapOperator) Parameter(dr.inference.model.Parameter)

Example 50 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class UniformOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    if (parameter.getDimension() == 0) {
        throw new XMLParseException("parameter with 0 dimension.");
    }
    Double lower = null;
    Double upper = null;
    if (xo.hasAttribute(LOWER)) {
        lower = xo.getDoubleAttribute(LOWER);
    }
    if (xo.hasAttribute(UPPER)) {
        upper = xo.getDoubleAttribute(UPPER);
    }
    return new UniformOperator(parameter, weight, lower, upper);
}
Also used : Parameter(dr.inference.model.Parameter) UniformOperator(dr.inference.operators.UniformOperator)

Aggregations

Parameter (dr.inference.model.Parameter)397 TreeModel (dr.evomodel.tree.TreeModel)62 MatrixParameter (dr.inference.model.MatrixParameter)46 ArrayList (java.util.ArrayList)44 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)43 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)41 Units (dr.evolution.util.Units)36 XMLUnits (dr.evoxml.util.XMLUnits)36 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)30 Tree (dr.evolution.tree.Tree)25 DataType (dr.evolution.datatype.DataType)24 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)23 CompoundParameter (dr.inference.model.CompoundParameter)23 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)21 SitePatterns (dr.evolution.alignment.SitePatterns)20 HKY (dr.evomodel.substmodel.nucleotide.HKY)17 Likelihood (dr.inference.model.Likelihood)17 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)16 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)16 ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)16