Search in sources :

Example 1 with MaskedParameter

use of dr.inference.model.MaskedParameter 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) {
        Parameter possiblyCompound = variable;
        if (variable instanceof MaskedParameter) {
            possiblyCompound = ((MaskedParameter) variable).getUnmaskedParameter();
        }
        if (!(possiblyCompound 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) MaskedParameter(dr.inference.model.MaskedParameter) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) MultivariateNormalDistributionModel(dr.inference.distribution.MultivariateNormalDistributionModel) CompoundParameter(dr.inference.model.CompoundParameter) MaskedParameter(dr.inference.model.MaskedParameter) Parameter(dr.inference.model.Parameter) EllipticalSliceOperator(dr.inference.operators.EllipticalSliceOperator) MultivariateNormalDistribution(dr.math.distributions.MultivariateNormalDistribution)

Example 2 with MaskedParameter

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

the class MaskedParameterParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    Parameter mask;
    XMLObject cxo = xo.getChild(MASKING);
    if (cxo != null) {
        mask = (Parameter) cxo.getChild(Parameter.class);
    } else if (xo.getAttribute(BUILD, false)) {
        mask = new Parameter.Default(parameter.getDimension(), 0.0);
        for (int i = 0; i < parameter.getDimension(); i++) {
            if (parameter.getParameterValue(i) == 0) {
                mask.setParameterValue(i, 1.0);
            }
        }
    } else {
        int from = xo.getAttribute(FROM, 1) - 1;
        int to = xo.getAttribute(TO, parameter.getDimension()) - 1;
        int every = xo.getAttribute(EVERY, 1);
        if (from < 0)
            throw new XMLParseException("illegal 'from' attribute in " + MASKED_PARAMETER + " element");
        if (to < 0 || to < from)
            throw new XMLParseException("illegal 'to' attribute in " + MASKED_PARAMETER + " element");
        if (every <= 0)
            throw new XMLParseException("illegal 'every' attribute in " + MASKED_PARAMETER + " element");
        mask = new Parameter.Default(parameter.getDimension(), 0.0);
        for (int i = from; i <= to; i += every) {
            mask.setParameterValue(i, 1.0);
        }
    }
    if (mask.getDimension() != parameter.getDimension())
        throw new XMLParseException("dim(" + parameter.getId() + ":" + parameter.getDimension() + ") != dim(" + mask.getId() + ":" + mask.getDimension() + ")");
    boolean signal = xo.getAttribute(SIGNAL_DEPENDENTS, true);
    MaskedParameter maskedParameter = new MaskedParameter(parameter, signal ? MaskedParameter.Signaling.NORMAL : MaskedParameter.Signaling.NO_DEPENDENT);
    boolean ones = !xo.getAttribute(COMPLEMENT, false);
    maskedParameter.addMask(mask, ones);
    return maskedParameter;
}
Also used : MaskedParameter(dr.inference.model.MaskedParameter) MaskedParameter(dr.inference.model.MaskedParameter) Parameter(dr.inference.model.Parameter)

Example 3 with MaskedParameter

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

the class MaskedMatrixParameterParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    MatrixParameter matrix = (MatrixParameter) xo.getChild(MatrixParameter.class);
    // System.err.println("colDim " + matrix.getColumnDimension());
    // System.err.println("rowDim " + matrix.getRowDimension());
    // System.err.println("parDim " + matrix.getParameterCount());
    Parameter mask;
    XMLObject cxo = xo.getChild(MASKING);
    if (cxo != null) {
        mask = (Parameter) cxo.getChild(Parameter.class);
    } else {
        int from = xo.getAttribute(FROM, 1) - 1;
        int to = xo.getAttribute(TO, matrix.getRowDimension()) - 1;
        int every = xo.getAttribute(EVERY, 1);
        if (from < 0)
            throw new XMLParseException("illegal 'from' attribute in " + MASKED_MATRIX_PARAMETER + " element");
        if (to < 0 || to < from)
            throw new XMLParseException("illegal 'to' attribute in " + MASKED_MATRIX_PARAMETER + " element");
        if (every <= 0)
            throw new XMLParseException("illegal 'every' attribute in " + MASKED_MATRIX_PARAMETER + " element");
        mask = new Parameter.Default(matrix.getRowDimension(), 0.0);
        for (int i = from; i <= to; i += every) {
            mask.setParameterValue(i, 1.0);
        }
    }
    if (mask.getDimension() != matrix.getRowDimension())
        throw new XMLParseException("rowDim(" + matrix.getId() + ") != dim(" + mask.getId() + ")");
    boolean ones = !xo.getAttribute(COMPLEMENT, false);
    MaskedParameter[] maskedParameters = new MaskedParameter[matrix.getColumnDimension()];
    for (int col = 0; col < matrix.getColumnDimension(); ++col) {
        maskedParameters[col] = new MaskedParameter(matrix.getParameter(col));
        maskedParameters[col].addMask(mask, ones);
    }
    MatrixParameter maskedMatrix = new MatrixParameter(matrix.getId() + ".masked", maskedParameters);
    return maskedMatrix;
}
Also used : MaskedParameter(dr.inference.model.MaskedParameter) MatrixParameter(dr.inference.model.MatrixParameter) MaskedParameter(dr.inference.model.MaskedParameter) Parameter(dr.inference.model.Parameter) MatrixParameter(dr.inference.model.MatrixParameter)

Aggregations

MaskedParameter (dr.inference.model.MaskedParameter)3 Parameter (dr.inference.model.Parameter)3 MultivariateDistributionLikelihood (dr.inference.distribution.MultivariateDistributionLikelihood)1 MultivariateNormalDistributionModel (dr.inference.distribution.MultivariateNormalDistributionModel)1 CompoundParameter (dr.inference.model.CompoundParameter)1 MatrixParameter (dr.inference.model.MatrixParameter)1 EllipticalSliceOperator (dr.inference.operators.EllipticalSliceOperator)1 GaussianProcessRandomGenerator (dr.math.distributions.GaussianProcessRandomGenerator)1 MultivariateNormalDistribution (dr.math.distributions.MultivariateNormalDistribution)1