Search in sources :

Example 1 with CachedDistributionLikelihood

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

the class CachedDistributionLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final String name = xo.hasId() ? xo.getId() : CACHED_PRIOR;
    final AbstractDistributionLikelihood likelihood = (AbstractDistributionLikelihood) xo.getChild(AbstractDistributionLikelihood.class);
    final Variable variable = (Variable) xo.getChild(Variable.class);
    final Logger logger = Logger.getLogger("dr.inference");
    logger.info("Constructing a cache around likelihood '" + likelihood.getId() + "', signal = " + variable.getVariableName());
    return new CachedDistributionLikelihood(name, likelihood, variable);
}
Also used : Variable(dr.inference.model.Variable) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) Logger(java.util.logging.Logger)

Example 2 with CachedDistributionLikelihood

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

the class ManyUniformGeoDistributionModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    List<GeoSpatialDistribution> distributions = new ArrayList<GeoSpatialDistribution>();
    List<Parameter> parameters = new ArrayList<Parameter>();
    List<Likelihood> oldLikelihood = new ArrayList<Likelihood>();
    for (int i = 0; i < xo.getChildCount(); ++i) {
        Object cxo = xo.getChild(i);
        MultivariateDistributionLikelihood ab = null;
        if (cxo instanceof MultivariateDistributionLikelihood) {
            ab = (MultivariateDistributionLikelihood) cxo;
        } else if (cxo instanceof CachedDistributionLikelihood) {
            ab = (MultivariateDistributionLikelihood) ((CachedDistributionLikelihood) cxo).getDistributionLikelihood();
        }
        if (ab != null) {
            parameters.add(ab.getDataParameter());
            MultivariateDistribution md = ab.getDistribution();
            oldLikelihood.add((Likelihood) cxo);
            if (md instanceof GeoSpatialDistribution) {
                distributions.add((GeoSpatialDistribution) md);
            } else {
                throw new XMLParseException("Unhandled distribution type in '" + xo.getId() + "'");
            }
        }
    }
    return new ManyUniformGeoDistributionModel(xo.getId(), parameters, distributions, oldLikelihood);
}
Also used : MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) Likelihood(dr.inference.model.Likelihood) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood) ArrayList(java.util.ArrayList) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) MultivariateDistribution(dr.math.distributions.MultivariateDistribution) Parameter(dr.inference.model.Parameter)

Example 3 with CachedDistributionLikelihood

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

Aggregations

AbstractDistributionLikelihood (dr.inference.distribution.AbstractDistributionLikelihood)3 CachedDistributionLikelihood (dr.inference.distribution.CachedDistributionLikelihood)3 MultivariateDistributionLikelihood (dr.inference.distribution.MultivariateDistributionLikelihood)2 Parameter (dr.inference.model.Parameter)2 ArrayList (java.util.ArrayList)2 AbstractPolygon2D (dr.geo.AbstractPolygon2D)1 GeoSpatialDistribution (dr.geo.GeoSpatialDistribution)1 MultiRegionGeoSpatialDistribution (dr.geo.MultiRegionGeoSpatialDistribution)1 Likelihood (dr.inference.model.Likelihood)1 Variable (dr.inference.model.Variable)1 MultivariateDistribution (dr.math.distributions.MultivariateDistribution)1 Logger (java.util.logging.Logger)1