Search in sources :

Example 11 with MultivariateDistributionLikelihood

use of dr.inference.distribution.MultivariateDistributionLikelihood in project beast-mcmc by beast-dev.

the class UniformGeoSpatialOperatorParser 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.");
    }
    MultivariateDistributionLikelihood likelihood = (MultivariateDistributionLikelihood) xo.getChild(MultivariateDistributionLikelihood.class);
    if (likelihood == null) {
        CachedDistributionLikelihood cached = (CachedDistributionLikelihood) xo.getChild(CachedDistributionLikelihood.class);
        AbstractDistributionLikelihood ab = cached.getDistributionLikelihood();
        if (!(ab instanceof MultivariateDistributionLikelihood)) {
            throw new XMLParseException("invalid likelihood type in " + xo.getId());
        }
        likelihood = (MultivariateDistributionLikelihood) ab;
    }
    List<AbstractPolygon2D> polygonList = new ArrayList<AbstractPolygon2D>();
    if (likelihood.getDistribution() instanceof MultiRegionGeoSpatialDistribution) {
        for (GeoSpatialDistribution spatial : ((MultiRegionGeoSpatialDistribution) likelihood.getDistribution()).getRegions()) {
            polygonList.add(spatial.getRegion());
        }
    } else if (likelihood.getDistribution() instanceof GeoSpatialDistribution) {
        polygonList.add(((GeoSpatialDistribution) likelihood.getDistribution()).getRegion());
    } else {
        throw new XMLParseException("Multivariate distribution must be either a GeoSpatialDistribution " + "or a MultiRegionGeoSpatialDistribution");
    }
    return new UniformGeoSpatialOperator(parameter, weight, polygonList);
}
Also used : AbstractPolygon2D(dr.geo.AbstractPolygon2D) GeoSpatialDistribution(dr.geo.GeoSpatialDistribution) MultiRegionGeoSpatialDistribution(dr.geo.MultiRegionGeoSpatialDistribution) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood) ArrayList(java.util.ArrayList) Parameter(dr.inference.model.Parameter) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) MultiRegionGeoSpatialDistribution(dr.geo.MultiRegionGeoSpatialDistribution)

Example 12 with MultivariateDistributionLikelihood

use of dr.inference.distribution.MultivariateDistributionLikelihood 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)

Example 13 with MultivariateDistributionLikelihood

use of dr.inference.distribution.MultivariateDistributionLikelihood in project beast-mcmc by beast-dev.

the class GMRFSkyrideFixedEffectsGibbsOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    GMRFSkyrideLikelihood gmrfLikelihood = (GMRFSkyrideLikelihood) xo.getChild(GMRFSkyrideLikelihood.class);
    MultivariateDistributionLikelihood likelihood = (MultivariateDistributionLikelihood) xo.getChild(MultivariateDistributionLikelihood.class);
    MultivariateDistribution prior = likelihood.getDistribution();
    if (prior.getType().compareTo(MultivariateNormalDistribution.TYPE) != 0)
        throw new XMLParseException("Only a multivariate normal distribution is conjugate for the regression coefficients in a GMRF");
    Parameter param = (Parameter) xo.getChild(Parameter.class);
    return new GMRFSkyrideFixedEffectsGibbsOperator(param, gmrfLikelihood, prior, weight);
}
Also used : MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) MultivariateDistribution(dr.math.distributions.MultivariateDistribution) GMRFSkyrideLikelihood(dr.evomodel.coalescent.GMRFSkyrideLikelihood) Parameter(dr.inference.model.Parameter) GMRFSkyrideFixedEffectsGibbsOperator(dr.evomodel.coalescent.operators.GMRFSkyrideFixedEffectsGibbsOperator)

Aggregations

MultivariateDistributionLikelihood (dr.inference.distribution.MultivariateDistributionLikelihood)13 Parameter (dr.inference.model.Parameter)8 ArrayList (java.util.ArrayList)8 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)6 AbstractDistributionLikelihood (dr.inference.distribution.AbstractDistributionLikelihood)3 CachedDistributionLikelihood (dr.inference.distribution.CachedDistributionLikelihood)3 GradientWrtParameterProvider (dr.inference.hmc.GradientWrtParameterProvider)3 Likelihood (dr.inference.model.Likelihood)3 GaussianProcessRandomGenerator (dr.math.distributions.GaussianProcessRandomGenerator)2 MultivariateDistribution (dr.math.distributions.MultivariateDistribution)2 MultivariateNormalDistribution (dr.math.distributions.MultivariateNormalDistribution)2 Attribute (dr.util.Attribute)2 GMRFSkyrideLikelihood (dr.evomodel.coalescent.GMRFSkyrideLikelihood)1 GMRFSkyrideFixedEffectsGibbsOperator (dr.evomodel.coalescent.operators.GMRFSkyrideFixedEffectsGibbsOperator)1 AbstractPolygon2D (dr.geo.AbstractPolygon2D)1 GeoSpatialDistribution (dr.geo.GeoSpatialDistribution)1 MultiRegionGeoSpatialDistribution (dr.geo.MultiRegionGeoSpatialDistribution)1 EmpiricalDistributionLikelihood (dr.inference.distribution.EmpiricalDistributionLikelihood)1 MultivariateNormalDistributionModel (dr.inference.distribution.MultivariateNormalDistributionModel)1 NormalDistributionModel (dr.inference.distribution.NormalDistributionModel)1