use of dr.evomodel.treedatalikelihood.continuous.ContinuousTraitDataModel 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;
}
Aggregations