Search in sources :

Example 26 with TreeDataLikelihood

use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.

the class ContinuousDataLikelihoodDelegateTest method testLikelihoodDiagonalOUBM.

public void testLikelihoodDiagonalOUBM() {
    System.out.println("\nTest Likelihood using Diagonal OU / BM:");
    // Diffusion
    List<BranchRateModel> optimalTraitsModels = new ArrayList<BranchRateModel>();
    optimalTraitsModels.add(new StrictClockBranchRates(new Parameter.Default("rate.1", new double[] { 1.0 })));
    optimalTraitsModels.add(new StrictClockBranchRates(new Parameter.Default("rate.2", new double[] { 2.0 })));
    optimalTraitsModels.add(new StrictClockBranchRates(new Parameter.Default("rate.3", new double[] { -2.0 })));
    DiagonalMatrix strengthOfSelectionMatrixParam = new DiagonalMatrix(new Parameter.Default(new double[] { 0.0, 0.000001, 50.0 }));
    DiffusionProcessDelegate diffusionProcessDelegate = new OUDiffusionModelDelegate(treeModel, diffusionModel, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParam));
    // CDL
    ContinuousDataLikelihoodDelegate likelihoodDelegate = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModel, rootPrior, rateTransformation, rateModel, false);
    // Likelihood Computation
    TreeDataLikelihood dataLikelihood = new TreeDataLikelihood(likelihoodDelegate, treeModel, rateModel);
    testLikelihood("likelihoodDiagonalOUBM", dataLikelihood);
    // Conditional moments (preorder)
    testConditionalMoments(dataLikelihood, likelihoodDelegate);
    // Fixed Root
    ContinuousDataLikelihoodDelegate likelihoodDelegateInf = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModel, rootPriorInf, rateTransformation, rateModel, true);
    TreeDataLikelihood dataLikelihoodInf = new TreeDataLikelihood(likelihoodDelegateInf, treeModel, rateModel);
    testLikelihood("likelihoodDiagonalOUBMInf", dataLikelihoodInf);
    testConditionalMoments(dataLikelihoodInf, likelihoodDelegateInf);
}
Also used : ArrayList(java.util.ArrayList) MultivariateElasticModel(dr.evomodel.continuous.MultivariateElasticModel) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) DiagonalMatrix(dr.inference.model.DiagonalMatrix) MatrixParameter(dr.inference.model.MatrixParameter) Parameter(dr.inference.model.Parameter)

Example 27 with TreeDataLikelihood

use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.

the class ContinuousDataLikelihoodDelegateTest method testLikelihoodFullAndDiagonalOU.

public void testLikelihoodFullAndDiagonalOU() {
    System.out.println("\nTest Likelihood comparing Full and Diagonal OU:");
    // Diffusion
    List<BranchRateModel> optimalTraitsModels = new ArrayList<BranchRateModel>();
    ArbitraryBranchRates.BranchRateTransform transform = make(false, false, false);
    optimalTraitsModels.add(new ArbitraryBranchRates(treeModel, new Parameter.Default("rate.1", new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }), transform, false));
    optimalTraitsModels.add(new ArbitraryBranchRates(treeModel, new Parameter.Default("rate.2", new double[] { 0, -1, 2, -3, 4, -5, 6, -7, 8, -9 }), transform, false));
    optimalTraitsModels.add(new StrictClockBranchRates(new Parameter.Default("rate.3", new double[] { -2.0 })));
    Parameter[] strengthOfSelectionParameters = new Parameter[3];
    strengthOfSelectionParameters[0] = new Parameter.Default(new double[] { 0.5, 0.0, 0.0 });
    strengthOfSelectionParameters[1] = new Parameter.Default(new double[] { 0.0, 10.5, 0.0 });
    strengthOfSelectionParameters[2] = new Parameter.Default(new double[] { 0.0, 0.0, 100.0 });
    MatrixParameter strengthOfSelectionMatrixParam = new MatrixParameter("strengthOfSelectionMatrix", strengthOfSelectionParameters);
    DiagonalMatrix strengthOfSelectionMatrixParamDiagonal = new DiagonalMatrix(new Parameter.Default(new double[] { 0.5, 10.5, 100.0 }));
    DiffusionProcessDelegate diffusionProcessDelegate = new OUDiffusionModelDelegate(treeModel, diffusionModel, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParam));
    DiffusionProcessDelegate diffusionProcessDelegateDiagonal = new OUDiffusionModelDelegate(treeModel, diffusionModel, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParamDiagonal));
    // CDL
    ContinuousDataLikelihoodDelegate likelihoodDelegate = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModel, rootPrior, rateTransformation, rateModel, false);
    ContinuousDataLikelihoodDelegate likelihoodDelegateDiagonal = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegateDiagonal, dataModel, rootPrior, rateTransformation, rateModel, false);
    // Likelihood Computation
    TreeDataLikelihood dataLikelihood = new TreeDataLikelihood(likelihoodDelegate, treeModel, rateModel);
    TreeDataLikelihood dataLikelihoodDiagonal = new TreeDataLikelihood(likelihoodDelegateDiagonal, treeModel, rateModel);
    assertEquals("likelihoodFullDiagonalOU", format.format(dataLikelihood.getLogLikelihood()), format.format(dataLikelihoodDiagonal.getLogLikelihood()));
}
Also used : MatrixParameter(dr.inference.model.MatrixParameter) ArrayList(java.util.ArrayList) MultivariateElasticModel(dr.evomodel.continuous.MultivariateElasticModel) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) ArbitraryBranchRates(dr.evomodel.branchratemodel.ArbitraryBranchRates) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) DiagonalMatrix(dr.inference.model.DiagonalMatrix) MatrixParameter(dr.inference.model.MatrixParameter) Parameter(dr.inference.model.Parameter)

Example 28 with TreeDataLikelihood

use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.

the class BranchSubstitutionParameterGradientParser 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 TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
    BranchSpecificSubstitutionParameterBranchModel branchModel = (BranchSpecificSubstitutionParameterBranchModel) xo.getChild(BranchModel.class);
    BeagleDataLikelihoodDelegate beagleData = (BeagleDataLikelihoodDelegate) treeDataLikelihood.getDataLikelihoodDelegate();
    BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    CompoundParameter branchParameter = branchModel.getBranchSpecificParameters(branchRateModel);
    return new BranchSubstitutionParameterGradient(traitName, treeDataLikelihood, beagleData, branchParameter, branchRateModel, useHessian);
}
Also used : CompoundParameter(dr.inference.model.CompoundParameter) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) BranchSpecificSubstitutionParameterBranchModel(dr.evomodel.branchmodel.BranchSpecificSubstitutionParameterBranchModel) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) BranchSubstitutionParameterGradient(dr.evomodel.treedatalikelihood.discrete.BranchSubstitutionParameterGradient) BranchSpecificSubstitutionParameterBranchModel(dr.evomodel.branchmodel.BranchSpecificSubstitutionParameterBranchModel) BranchModel(dr.evomodel.branchmodel.BranchModel)

Example 29 with TreeDataLikelihood

use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.

the class DiffusionGradientParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
    List<ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter> derivationParametersList = new ArrayList<ContinuousTraitGradientForBranch.ContinuousProcessParameterGradient.DerivationParameter>();
    CompoundParameter compoundParameter = new CompoundParameter(null);
    List<GradientWrtParameterProvider> derivativeList = new ArrayList<GradientWrtParameterProvider>();
    List<AbstractDiffusionGradient> diffGradients = xo.getAllChildren(AbstractDiffusionGradient.class);
    if (diffGradients != null) {
        for (AbstractDiffusionGradient grad : diffGradients) {
            derivationParametersList.add(grad.getDerivationParameter());
            compoundParameter.addParameter(grad.getRawParameter());
            derivativeList.add(grad);
        }
    }
    CompoundGradient parametersGradients = new CompoundDerivative(derivativeList);
    // testSameModel(precisionGradient, attenuationGradient);
    TreeDataLikelihood treeDataLikelihood = ((TreeDataLikelihood) diffGradients.get(0).getLikelihood());
    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, derivationParametersList);
    BranchSpecificGradient branchSpecificGradient = new BranchSpecificGradient(traitName, treeDataLikelihood, continuousData, traitGradient, compoundParameter);
    return new DiffusionParametersGradient(branchSpecificGradient, parametersGradients);
}
Also used : CompoundGradient(dr.inference.hmc.CompoundGradient) BranchSpecificGradient(dr.evomodel.treedatalikelihood.continuous.BranchSpecificGradient) AbstractDiffusionGradient(dr.evomodel.treedatalikelihood.hmc.AbstractDiffusionGradient) ArrayList(java.util.ArrayList) CompoundParameter(dr.inference.model.CompoundParameter) DiffusionParametersGradient(dr.evomodel.treedatalikelihood.hmc.DiffusionParametersGradient) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) CompoundDerivative(dr.inference.hmc.CompoundDerivative) GradientWrtParameterProvider(dr.inference.hmc.GradientWrtParameterProvider) Tree(dr.evolution.tree.Tree) ContinuousTraitGradientForBranch(dr.evomodel.treedatalikelihood.continuous.ContinuousTraitGradientForBranch) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)

Example 30 with TreeDataLikelihood

use of dr.evomodel.treedatalikelihood.TreeDataLikelihood in project beast-mcmc by beast-dev.

the class TreePrecisionDataProductProviderParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String traitName = xo.getAttribute(TRAIT_NAME, DEFAULT_TRAIT_NAME);
    TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
    DataLikelihoodDelegate delegate = treeDataLikelihood.getDataLikelihoodDelegate();
    if (!(delegate instanceof ContinuousDataLikelihoodDelegate)) {
        throw new XMLParseException("May not provide a sequence data likelihood to compute tip trait gradient");
    }
    ContinuousDataLikelihoodDelegate continuousData = (ContinuousDataLikelihoodDelegate) delegate;
    return parseComputeMode(xo, treeDataLikelihood, continuousData, traitName);
}
Also used : TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)

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