Search in sources :

Example 1 with GaussianProcessRandomGenerator

use of dr.math.distributions.GaussianProcessRandomGenerator 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 GaussianProcessRandomGenerator

use of dr.math.distributions.GaussianProcessRandomGenerator in project beast-mcmc by beast-dev.

the class CompoundGaussianProcessParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    List<GaussianProcessRandomGenerator> gpList = new ArrayList<GaussianProcessRandomGenerator>();
    List<Likelihood> likelihoodList = new ArrayList<Likelihood>();
    List<Integer> copyList = new ArrayList<Integer>();
    for (int i = 0; i < xo.getChildCount(); ++i) {
        Object obj = xo.getChild(i);
        GaussianProcessRandomGenerator gp = null;
        Likelihood likelihood = null;
        int copies = -1;
        if (obj instanceof DistributionLikelihood) {
            DistributionLikelihood dl = (DistributionLikelihood) obj;
            if (!(dl.getDistribution() instanceof GaussianProcessRandomGenerator)) {
                throw new XMLParseException("Not a Gaussian process");
            }
            likelihood = dl;
            gp = (GaussianProcessRandomGenerator) dl.getDistribution();
            copies = 0;
            for (Attribute<double[]> datum : dl.getDataList()) {
                // Double draw = (Double) gp.nextRandom();
                // System.err.println("DL: " + datum.getAttributeName() + " " + datum.getAttributeValue().length + " " + "1");
                copies += datum.getAttributeValue().length;
            }
        } else if (obj instanceof MultivariateDistributionLikelihood) {
            MultivariateDistributionLikelihood mdl = (MultivariateDistributionLikelihood) obj;
            if (!(mdl.getDistribution() instanceof GaussianProcessRandomGenerator)) {
                throw new XMLParseException("Not a Gaussian process");
            }
            likelihood = mdl;
            gp = (GaussianProcessRandomGenerator) mdl.getDistribution();
            copies = 0;
            double[] draw = (double[]) gp.nextRandom();
            for (Attribute<double[]> datum : mdl.getDataList()) {
                // System.err.println("ML: " + datum.getAttributeName() + " " + datum.getAttributeValue().length + " " + draw.length);
                copies += datum.getAttributeValue().length / draw.length;
            }
        } else if (obj instanceof GaussianProcessRandomGenerator) {
            gp = (GaussianProcessRandomGenerator) obj;
            likelihood = gp.getLikelihood();
            copies = 1;
        } else {
            throw new XMLParseException("Not a Gaussian process");
        }
        gpList.add(gp);
        likelihoodList.add(likelihood);
        copyList.add(copies);
    }
    // System.exit(-1);
    return new CompoundGaussianProcess(gpList, likelihoodList, copyList);
}
Also used : MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) Attribute(dr.util.Attribute) Likelihood(dr.inference.model.Likelihood) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood) CompoundGaussianProcess(dr.math.distributions.CompoundGaussianProcess) ArrayList(java.util.ArrayList) GaussianProcessRandomGenerator(dr.math.distributions.GaussianProcessRandomGenerator) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood)

Aggregations

MultivariateDistributionLikelihood (dr.inference.distribution.MultivariateDistributionLikelihood)2 GaussianProcessRandomGenerator (dr.math.distributions.GaussianProcessRandomGenerator)2 AbstractDistributionLikelihood (dr.inference.distribution.AbstractDistributionLikelihood)1 CachedDistributionLikelihood (dr.inference.distribution.CachedDistributionLikelihood)1 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)1 MultivariateNormalDistributionModel (dr.inference.distribution.MultivariateNormalDistributionModel)1 CompoundParameter (dr.inference.model.CompoundParameter)1 Likelihood (dr.inference.model.Likelihood)1 MaskedParameter (dr.inference.model.MaskedParameter)1 Parameter (dr.inference.model.Parameter)1 EllipticalSliceOperator (dr.inference.operators.EllipticalSliceOperator)1 CompoundGaussianProcess (dr.math.distributions.CompoundGaussianProcess)1 MultivariateNormalDistribution (dr.math.distributions.MultivariateNormalDistribution)1 Attribute (dr.util.Attribute)1 ArrayList (java.util.ArrayList)1