Search in sources :

Example 16 with DistributionLikelihood

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

the class ModelSpecificPseudoPriorLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    DistributionLikelihood priorLikelihood = (DistributionLikelihood) xo.getElementFirstChild(PRIOR);
    DistributionLikelihood pseudoPriorLikelihood = (DistributionLikelihood) xo.getElementFirstChild(PSEUDO_PRIOR);
    Distribution prior = priorLikelihood.getDistribution();
    Distribution pseudoPrior = pseudoPriorLikelihood.getDistribution();
    Parameter modelIndicator = (Parameter) xo.getElementFirstChild(MODEL_INDICATOR);
    int[] models = xo.getIntegerArrayAttribute(MODELS);
    Parameter selectedVariable = (Parameter) xo.getElementFirstChild(SELECTED_VARIABLE);
    ModelSpecificPseudoPriorLikelihood likelihood = new ModelSpecificPseudoPriorLikelihood(prior, pseudoPrior, modelIndicator, models);
    likelihood.addData(selectedVariable);
    return likelihood;
}
Also used : ModelSpecificPseudoPriorLikelihood(dr.inference.distribution.ModelSpecificPseudoPriorLikelihood) Distribution(dr.math.distributions.Distribution) Parameter(dr.inference.model.Parameter) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood)

Example 17 with DistributionLikelihood

use of dr.inference.distribution.DistributionLikelihood 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 18 with DistributionLikelihood

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

the class DistributionLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final XMLObject cxo = xo.getChild(DISTRIBUTION);
    ParametricDistributionModel model = (ParametricDistributionModel) cxo.getChild(ParametricDistributionModel.class);
    DistributionLikelihood likelihood = new DistributionLikelihood(model);
    XMLObject cxo1 = xo.getChild(DATA);
    final int from = cxo1.getAttribute(FROM, -1);
    int to = cxo1.getAttribute(TO, -1);
    if (from >= 0 || to >= 0) {
        if (to < 0) {
            to = Integer.MAX_VALUE;
        }
        if (!(from >= 0 && to >= 0 && from < to)) {
            throw new XMLParseException("ill formed from-to");
        }
        likelihood.setRange(from, to);
    }
    for (int j = 0; j < cxo1.getChildCount(); j++) {
        if (cxo1.getChild(j) instanceof Statistic) {
            likelihood.addData((Statistic) cxo1.getChild(j));
        } else {
            throw new XMLParseException("illegal element in " + cxo1.getName() + " element");
        }
    }
    return likelihood;
}
Also used : Statistic(dr.inference.model.Statistic) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood)

Aggregations

DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)18 ArrayList (java.util.ArrayList)9 Parameter (dr.inference.model.Parameter)7 MCLogger (dr.inference.loggers.MCLogger)5 MCMC (dr.inference.mcmc.MCMC)5 Likelihood (dr.inference.model.Likelihood)5 MultivariateDistributionLikelihood (dr.inference.distribution.MultivariateDistributionLikelihood)4 ArrayLogFormatter (dr.inference.loggers.ArrayLogFormatter)4 MCMCOptions (dr.inference.mcmc.MCMCOptions)4 CompoundLikelihood (dr.inference.model.CompoundLikelihood)4 NormalDistributionModel (dr.inference.distribution.NormalDistributionModel)3 ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)3 TabDelimitedFormatter (dr.inference.loggers.TabDelimitedFormatter)3 LatentFactorModel (dr.inference.model.LatentFactorModel)3 ArrayTraceList (dr.inference.trace.ArrayTraceList)3 Trace (dr.inference.trace.Trace)3 TraceCorrelation (dr.inference.trace.TraceCorrelation)3 Attribute (dr.util.Attribute)3 Taxa (dr.evolution.util.Taxa)2 Taxon (dr.evolution.util.Taxon)2