Search in sources :

Example 6 with TreeDataLikelihood

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");
    }
}
Also used : ArbitraryBranchRates(dr.evomodel.branchratemodel.ArbitraryBranchRates) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) Parameter(dr.inference.model.Parameter) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) NodeHeightGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.NodeHeightGradientForDiscreteTrait) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel)

Example 7 with TreeDataLikelihood

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);
}
Also used : ModelExtensionProvider(dr.evomodel.treedatalikelihood.preorder.ModelExtensionProvider) MatrixParameterInterface(dr.inference.model.MatrixParameterInterface) ArrayList(java.util.ArrayList) ConjugateWishartStatisticsProvider(dr.math.interfaces.ConjugateWishartStatisticsProvider) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) Tree(dr.evolution.tree.Tree)

Example 8 with TreeDataLikelihood

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;
}
Also used : TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) GaussianProcessFromTree(dr.evomodel.continuous.GaussianProcessFromTree) TreeTipGaussianProcess(dr.evomodel.treedatalikelihood.continuous.TreeTipGaussianProcess) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) FullyConjugateMultivariateTraitLikelihood(dr.evomodel.continuous.FullyConjugateMultivariateTraitLikelihood)

Example 9 with TreeDataLikelihood

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);
}
Also used : BranchSpecificGradient(dr.evomodel.treedatalikelihood.continuous.BranchSpecificGradient) MatrixParameterInterface(dr.inference.model.MatrixParameterInterface) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) Tree(dr.evolution.tree.Tree) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) ContinuousTraitGradientForBranch(dr.evomodel.treedatalikelihood.continuous.ContinuousTraitGradientForBranch)

Example 10 with TreeDataLikelihood

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);
    }
}
Also used : TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) CompoundLikelihood(dr.inference.model.CompoundLikelihood) Likelihood(dr.inference.model.Likelihood) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) CompoundLikelihood(dr.inference.model.CompoundLikelihood) GradientWrtParameterProvider(dr.inference.hmc.GradientWrtParameterProvider) ArrayList(java.util.ArrayList) SumDerivative(dr.inference.hmc.SumDerivative)

Aggregations

TreeDataLikelihood (dr.evomodel.treedatalikelihood.TreeDataLikelihood)45 ArrayList (java.util.ArrayList)29 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)25 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)23 StrictClockBranchRates (dr.evomodel.branchratemodel.StrictClockBranchRates)21 Parameter (dr.inference.model.Parameter)20 MultivariateElasticModel (dr.evomodel.continuous.MultivariateElasticModel)17 MatrixParameter (dr.inference.model.MatrixParameter)15 DataLikelihoodDelegate (dr.evomodel.treedatalikelihood.DataLikelihoodDelegate)12 ArbitraryBranchRates (dr.evomodel.branchratemodel.ArbitraryBranchRates)11 Tree (dr.evolution.tree.Tree)8 ContinuousDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)8 DiagonalMatrix (dr.inference.model.DiagonalMatrix)8 BeagleDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate)6 Likelihood (dr.inference.model.Likelihood)6 Taxon (dr.evolution.util.Taxon)4 MultiPartitionDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.MultiPartitionDataLikelihoodDelegate)4 CompoundLikelihood (dr.inference.model.CompoundLikelihood)4 MatrixParameterInterface (dr.inference.model.MatrixParameterInterface)4 GradientWrtParameterProvider (dr.inference.hmc.GradientWrtParameterProvider)3