use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.
the class NodeHeightGradientParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
final TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
BranchRateModel branchRateModel = treeDataLikelihood.getBranchRateModel();
if (branchRateModel instanceof DefaultBranchRateModel || branchRateModel instanceof ArbitraryBranchRates) {
Parameter branchRates = null;
if (branchRateModel instanceof ArbitraryBranchRates) {
branchRates = ((ArbitraryBranchRates) branchRateModel).getRateParameter();
}
DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
if (delegate instanceof ContinuousDataLikelihoodDelegate) {
throw new XMLParseException("Not yet implemented! ");
} else if (delegate instanceof BeagleDataLikelihoodDelegate) {
BeagleDataLikelihoodDelegate beagleData = (BeagleDataLikelihoodDelegate) delegate;
return new NodeHeightGradientForDiscreteTrait(traitName, treeDataLikelihood, beagleData, branchRates);
} else {
throw new XMLParseException("Unknown likelihood delegate type");
}
} else {
throw new XMLParseException("Only implemented for an arbitrary rates model");
}
}
use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.
the class PrecisionGradientParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
MatrixParameterInterface parameter = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class);
TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
GradientWrtPrecisionProvider gradientWrtPrecisionProvider;
ConjugateWishartStatisticsProvider wishartStatistics = (ConjugateWishartStatisticsProvider) xo.getChild(ConjugateWishartStatisticsProvider.class);
if (wishartStatistics != null) {
gradientWrtPrecisionProvider = new GradientWrtPrecisionProvider.WishartGradientWrtPrecisionProvider(wishartStatistics);
} else {
int dim = treeDataLikelihood.getDataLikelihoodDelegate().getTraitDim();
Tree tree = treeDataLikelihood.getTree();
DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
ContinuousDataLikelihoodDelegate continuousData = (ContinuousDataLikelihoodDelegate) delegate;
ModelExtensionProvider.NormalExtensionProvider extensionProvider = (ModelExtensionProvider.NormalExtensionProvider) xo.getChild(ModelExtensionProvider.NormalExtensionProvider.class);
ContinuousTraitGradientForBranch traitGradient;
if (extensionProvider != null) {
traitGradient = new ContinuousTraitGradientForBranch.SamplingVarianceGradient(dim, tree, continuousData, extensionProvider);
} else {
traitGradient = new ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient(dim, tree, continuousData, new ArrayList<>(Arrays.asList(ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter.WRT_VARIANCE)));
}
BranchSpecificGradient branchSpecificGradient = new BranchSpecificGradient(traitName, treeDataLikelihood, continuousData, traitGradient, parameter);
gradientWrtPrecisionProvider = new GradientWrtPrecisionProvider.BranchSpecificGradientWrtPrecisionProvider(branchSpecificGradient);
}
ParameterMode parameterMode = parseParameterMode(xo);
return parameterMode.factory(gradientWrtPrecisionProvider, treeDataLikelihood, parameter);
}
use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.
the class GaussianProcessFromTreeParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
FullyConjugateMultivariateTraitLikelihood traitModel = (FullyConjugateMultivariateTraitLikelihood) xo.getChild(FullyConjugateMultivariateTraitLikelihood.class);
if (traitModel != null) {
return new GaussianProcessFromTree(traitModel);
}
TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
ContinuousDataLikelihoodDelegate dataDelegate = GibbsSampleMissingTraitsOperator.parseContinuousDataLikelihoodDelegate(xo);
boolean mask = xo.getAttribute(MASK_TO_MISSING, true);
TreeTipGaussianProcess process = new TreeTipGaussianProcess(dataDelegate.getDataModel().getModelName(), treeDataLikelihood, dataDelegate, null, true);
return process;
}
use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.
the class AttenuationGradientParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
MatrixParameterInterface parameter = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class);
TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
int dim = treeDataLikelihood.getDataLikelihoodDelegate().getTraitDim();
Tree tree = treeDataLikelihood.getTree();
ContinuousDataLikelihoodDelegate continuousData = (ContinuousDataLikelihoodDelegate) delegate;
ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient traitGradient = new ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient(dim, tree, continuousData, new ArrayList<ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter>(Arrays.asList(ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter.WRT_DIAGONAL_SELECTION_STRENGTH)));
BranchSpecificGradient branchSpecificGradient = new BranchSpecificGradient(traitName, treeDataLikelihood, continuousData, traitGradient, parameter);
ParameterMode parameterMode = parseParameterMode(xo);
return parameterMode.factory(branchSpecificGradient, treeDataLikelihood, parameter);
}
use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.
the class BranchRateGradientParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
boolean useHessian = xo.getAttribute(USE_HESSIAN, false);
final Object child = xo.getChild(TreeDataLikelihood.class);
if (child != null) {
return parseTreeDataLikelihood((TreeDataLikelihood) child, traitName, useHessian);
} else {
CompoundLikelihood compoundLikelihood = (CompoundLikelihood) xo.getChild(CompoundLikelihood.class);
List<GradientWrtParameterProvider> providers = new ArrayList<>();
for (Likelihood likelihood : compoundLikelihood.getLikelihoods()) {
if (!(likelihood instanceof TreeDataLikelihood)) {
throw new XMLParseException("Unknown likelihood type");
}
GradientWrtParameterProvider provider = parseTreeDataLikelihood((TreeDataLikelihood) likelihood, traitName, useHessian);
providers.add(provider);
}
checkBranchRateModels(providers);
return new SumDerivative(providers);
}
}
Aggregations