Search in sources :

Example 1 with MultivariateDiffusionModel

use of dr.evomodel.continuous.MultivariateDiffusionModel in project beast-mcmc by beast-dev.

the class ContinuousDataLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    MultivariateDiffusionModel diffusionModel = (MultivariateDiffusionModel) xo.getChild(MultivariateDiffusionModel.class);
    BranchRateModel rateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    TreeTraitParserUtilities utilities = new TreeTraitParserUtilities();
    String traitName = TreeTraitParserUtilities.DEFAULT_TRAIT_NAME;
    TreeTraitParserUtilities.TraitsAndMissingIndices returnValue = utilities.parseTraitsFromTaxonAttributes(xo, traitName, treeModel, true);
    CompoundParameter traitParameter = returnValue.traitParameter;
    List<Integer> missingIndices = returnValue.missingIndices;
    Parameter sampleMissingParameter = returnValue.sampleMissingParameter;
    traitName = returnValue.traitName;
    final int dim = diffusionModel.getPrecisionmatrix().length;
    PrecisionType precisionType = PrecisionType.SCALAR;
    if (missingIndices.size() > 0 && !xo.getAttribute(FORCE_COMPLETELY_MISSING, false)) {
        precisionType = PrecisionType.FULL;
    }
    System.err.println("Using precisionType == " + precisionType + " for data model.");
    ContinuousTraitDataModel dataModel = new ContinuousTraitDataModel(traitName, traitParameter, missingIndices, dim, precisionType);
    ConjugateRootTraitPrior rootPrior = ConjugateRootTraitPrior.parseConjugateRootTraitPrior(xo, dim);
    boolean useTreeLength = xo.getAttribute(USE_TREE_LENGTH, false);
    boolean scaleByTime = xo.getAttribute(SCALE_BY_TIME, false);
    if (rateModel == null) {
        rateModel = new DefaultBranchRateModel();
    }
    ContinuousRateTransformation rateTransformation = new ContinuousRateTransformation.Default(treeModel, scaleByTime, useTreeLength);
    ContinuousDataLikelihoodDelegate delegate = new ContinuousDataLikelihoodDelegate(treeModel, diffusionModel, dataModel, rootPrior, rateTransformation, rateModel);
    TreeDataLikelihood treeDataLikelihood = new TreeDataLikelihood(delegate, treeModel, rateModel);
    boolean reconstructTraits = xo.getAttribute(RECONSTRUCT_TRAITS, true);
    if (reconstructTraits) {
        if (missingIndices.size() == 0) {
            ProcessSimulationDelegate simulationDelegate = new ProcessSimulationDelegate.ConditionalOnTipsRealizedDelegate(traitName, treeModel, diffusionModel, dataModel, rootPrior, rateTransformation, rateModel, delegate);
            TreeTraitProvider traitProvider = new ProcessSimulation(traitName, treeDataLikelihood, simulationDelegate);
            treeDataLikelihood.addTraits(traitProvider.getTreeTraits());
        } else {
            ProcessSimulationDelegate simulationDelegate = delegate.getPrecisionType() == PrecisionType.SCALAR ? new ProcessSimulationDelegate.ConditionalOnTipsRealizedDelegate(traitName, treeModel, diffusionModel, dataModel, rootPrior, rateTransformation, rateModel, delegate) : new ProcessSimulationDelegate.MultivariateConditionalOnTipsRealizedDelegate(traitName, treeModel, diffusionModel, dataModel, rootPrior, rateTransformation, rateModel, delegate);
            TreeTraitProvider traitProvider = new ProcessSimulation(traitName, treeDataLikelihood, simulationDelegate);
            treeDataLikelihood.addTraits(traitProvider.getTreeTraits());
            ProcessSimulationDelegate fullConditionalDelegate = new ProcessSimulationDelegate.TipRealizedValuesViaFullConditionalDelegate(traitName, treeModel, diffusionModel, dataModel, rootPrior, rateTransformation, rateModel, delegate);
            treeDataLikelihood.addTraits(new ProcessSimulation(("fc." + traitName), treeDataLikelihood, fullConditionalDelegate).getTreeTraits());
        //                String partialTraitName = getPartiallyMissingTraitName(traitName);
        //
        //                ProcessSimulationDelegate parialSimulationDelegate = new ProcessSimulationDelegate.ConditionalOnPartiallyMissingTipsDelegate(partialTraitName,
        //                        treeModel, diffusionModel, dataModel, rootPrior, rateTransformation, rateModel, delegate);
        //
        //                TreeTraitProvider partialTraitProvider = new ProcessSimulation(partialTraitName,
        //                        treeDataLikelihood, parialSimulationDelegate);
        //
        //                treeDataLikelihood.addTraits(partialTraitProvider.getTreeTraits());
        }
    }
    return treeDataLikelihood;
}
Also used : PrecisionType(dr.evomodel.treedatalikelihood.continuous.cdi.PrecisionType) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) CompoundParameter(dr.inference.model.CompoundParameter) TreeModel(dr.evomodel.tree.TreeModel) MultivariateDiffusionModel(dr.evomodel.continuous.MultivariateDiffusionModel) ConjugateRootTraitPrior(dr.evomodel.treedatalikelihood.continuous.ConjugateRootTraitPrior) ContinuousTraitDataModel(dr.evomodel.treedatalikelihood.continuous.ContinuousTraitDataModel) TreeTraitProvider(dr.evolution.tree.TreeTraitProvider) ContinuousRateTransformation(dr.evomodel.treedatalikelihood.continuous.ContinuousRateTransformation) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) ProcessSimulation(dr.evomodel.treedatalikelihood.ProcessSimulation) TreeTraitParserUtilities(dr.evomodelxml.treelikelihood.TreeTraitParserUtilities) CompoundParameter(dr.inference.model.CompoundParameter) Parameter(dr.inference.model.Parameter) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) ProcessSimulationDelegate(dr.evomodel.treedatalikelihood.ProcessSimulationDelegate)

Aggregations

TreeTraitProvider (dr.evolution.tree.TreeTraitProvider)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)1 MultivariateDiffusionModel (dr.evomodel.continuous.MultivariateDiffusionModel)1 TreeModel (dr.evomodel.tree.TreeModel)1 ProcessSimulation (dr.evomodel.treedatalikelihood.ProcessSimulation)1 ProcessSimulationDelegate (dr.evomodel.treedatalikelihood.ProcessSimulationDelegate)1 TreeDataLikelihood (dr.evomodel.treedatalikelihood.TreeDataLikelihood)1 ConjugateRootTraitPrior (dr.evomodel.treedatalikelihood.continuous.ConjugateRootTraitPrior)1 ContinuousDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)1 ContinuousRateTransformation (dr.evomodel.treedatalikelihood.continuous.ContinuousRateTransformation)1 ContinuousTraitDataModel (dr.evomodel.treedatalikelihood.continuous.ContinuousTraitDataModel)1 PrecisionType (dr.evomodel.treedatalikelihood.continuous.cdi.PrecisionType)1 TreeTraitParserUtilities (dr.evomodelxml.treelikelihood.TreeTraitParserUtilities)1 CompoundParameter (dr.inference.model.CompoundParameter)1 Parameter (dr.inference.model.Parameter)1