Search in sources :

Example 6 with ArbitraryBranchRates

use of dr.evomodel.branchratemodel.ArbitraryBranchRates in project beast-mcmc by beast-dev.

the class ContinuousDataLikelihoodDelegateTest method testLikelihoodDiagonalOURelaxedFactor.

public void testLikelihoodDiagonalOURelaxedFactor() {
    System.out.println("\nTest Likelihood using diagonal Relaxed OU and factor:");
    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 StrictClockBranchRates(new Parameter.Default("rate.2", new double[] { -1.5 })));
    DiagonalMatrix strengthOfSelectionMatrixParam = new DiagonalMatrix(new Parameter.Default(new double[] { 1.5, 20.0 }));
    DiffusionProcessDelegate diffusionProcessDelegate = new OUDiffusionModelDelegate(treeModel, diffusionModelFactor, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParam));
    // CDL
    ContinuousDataLikelihoodDelegate likelihoodDelegateFactors = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModelFactor, rootPriorFactor, rateTransformation, rateModel, false);
    dataModelFactor.setLikelihoodDelegate(likelihoodDelegateFactors);
    // Likelihood Computation
    TreeDataLikelihood dataLikelihoodFactors = new TreeDataLikelihood(likelihoodDelegateFactors, treeModel, rateModel);
    testLikelihood("likelihoodDiagonalOURelaxedFactor", dataModelFactor, dataLikelihoodFactors);
    // Conditional simulations
    MathUtils.setSeed(17890826);
    double[] expectedTraits = new double[] { 1.2546097113922914, -1.1761389606670978, 1.305611773283861, -1.0644815941127401, 1.4571577864569687, -1.1477885449972944, 1.749551506462585, -0.9890375857170963, 1.0763987351136657, -1.0671848958534547, 1.5276137550128892, -0.9822950795368887 };
    testConditionalSimulations(dataLikelihoodFactors, likelihoodDelegateFactors, diffusionModelFactor, dataModelFactor, rootPriorFactor, expectedTraits);
}
Also used : 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 7 with ArbitraryBranchRates

use of dr.evomodel.branchratemodel.ArbitraryBranchRates in project beast-mcmc by beast-dev.

the class ContinuousDataLikelihoodDelegateTest method testLikelihoodFullDiagonalOUFactor.

public void testLikelihoodFullDiagonalOUFactor() {
    System.out.println("\nTest Likelihood comparing full and diagonal OU and factor:");
    // 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 StrictClockBranchRates(new Parameter.Default("rate.2", new double[] { 1.5 })));
    Parameter[] strengthOfSelectionParameters = new Parameter[2];
    strengthOfSelectionParameters[0] = new Parameter.Default(new double[] { 0.5, 0.0 });
    strengthOfSelectionParameters[1] = new Parameter.Default(new double[] { 0.0, 1.5 });
    MatrixParameter strengthOfSelectionMatrixParam = new MatrixParameter("strengthOfSelectionMatrix", strengthOfSelectionParameters);
    DiagonalMatrix strengthOfSelectionMatrixParamDiagonal = new DiagonalMatrix(new Parameter.Default(new double[] { 0.5, 1.5 }));
    DiffusionProcessDelegate diffusionProcessDelegate = new OUDiffusionModelDelegate(treeModel, diffusionModelFactor, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParam));
    DiffusionProcessDelegate diffusionProcessDelegateDiagonal = new OUDiffusionModelDelegate(treeModel, diffusionModelFactor, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParamDiagonal));
    // CDL
    ContinuousDataLikelihoodDelegate likelihoodDelegateFactors = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModelFactor, rootPriorFactor, rateTransformation, rateModel, false);
    ContinuousDataLikelihoodDelegate likelihoodDelegateFactorsDiagonal = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegateDiagonal, dataModelFactor, rootPriorFactor, rateTransformation, rateModel, false);
    dataModelFactor.setLikelihoodDelegate(likelihoodDelegateFactors);
    // Likelihood Computation
    TreeDataLikelihood dataLikelihoodFactors = new TreeDataLikelihood(likelihoodDelegateFactors, treeModel, rateModel);
    TreeDataLikelihood dataLikelihoodFactorsDiagonal = new TreeDataLikelihood(likelihoodDelegateFactorsDiagonal, treeModel, rateModel);
    double likelihoodFactorData = dataLikelihoodFactors.getLogLikelihood();
    double likelihoodFactorDiffusion = dataModelFactor.getLogLikelihood();
    double likelihoodFactorDataDiagonal = dataLikelihoodFactorsDiagonal.getLogLikelihood();
    double likelihoodFactorDiffusionDiagonal = dataModelFactor.getLogLikelihood();
    assertEquals("likelihoodFullDiagonalOUFactor", format.format(likelihoodFactorData + likelihoodFactorDiffusion), format.format(likelihoodFactorDataDiagonal + likelihoodFactorDiffusionDiagonal));
}
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 8 with ArbitraryBranchRates

use of dr.evomodel.branchratemodel.ArbitraryBranchRates 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 9 with ArbitraryBranchRates

use of dr.evomodel.branchratemodel.ArbitraryBranchRates in project beast-mcmc by beast-dev.

the class BranchRateGradientParser method parseTreeDataLikelihood.

private GradientWrtParameterProvider parseTreeDataLikelihood(TreeDataLikelihood treeDataLikelihood, String traitName, boolean useHessian) throws XMLParseException {
    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) {
            ContinuousDataLikelihoodDelegate continuousData = (ContinuousDataLikelihoodDelegate) delegate;
            return new BranchRateGradient(traitName, treeDataLikelihood, continuousData, branchRates);
        } else if (delegate instanceof BeagleDataLikelihoodDelegate) {
            BeagleDataLikelihoodDelegate beagleData = (BeagleDataLikelihoodDelegate) delegate;
            if (branchRateModel instanceof LocalBranchRates) {
                return new LocalBranchRateGradientForDiscreteTrait(traitName, treeDataLikelihood, beagleData, branchRates, useHessian);
            } else {
                return new BranchRateGradientForDiscreteTrait(traitName, treeDataLikelihood, beagleData, branchRates, useHessian);
            }
        } 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) 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) BranchRateGradient(dr.evomodel.treedatalikelihood.continuous.BranchRateGradient) BranchRateGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.BranchRateGradientForDiscreteTrait) LocalBranchRateGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.LocalBranchRateGradientForDiscreteTrait) LocalBranchRateGradientForDiscreteTrait(dr.evomodel.treedatalikelihood.discrete.LocalBranchRateGradientForDiscreteTrait) Parameter(dr.inference.model.Parameter) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) ContinuousDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) LocalBranchRates(dr.evomodel.branchratemodel.LocalBranchRates)

Example 10 with ArbitraryBranchRates

use of dr.evomodel.branchratemodel.ArbitraryBranchRates in project beast-mcmc by beast-dev.

the class RelaxedDriftModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    Parameter ratesParameter = (Parameter) xo.getElementFirstChild(RATES);
    Parameter rateIndicatorParameter = (Parameter) xo.getElementFirstChild(RATE_IND);
    Parameter driftRates = null;
    if (xo.hasChildNamed(DRIFT_RATES)) {
        driftRates = (Parameter) xo.getElementFirstChild(DRIFT_RATES);
    }
    ArbitraryBranchRates branchChanges = null;
    if (xo.hasChildNamed(BRANCH_CHANGES)) {
        branchChanges = (ArbitraryBranchRates) xo.getElementFirstChild(BRANCH_CHANGES);
    }
    Logger.getLogger("dr.evomodel").info("Using relaxed drift model.");
    return new RelaxedDriftModel(tree, rateIndicatorParameter, ratesParameter, driftRates, branchChanges);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) ArbitraryBranchRates(dr.evomodel.branchratemodel.ArbitraryBranchRates) RelaxedDriftModel(dr.evomodel.branchratemodel.RelaxedDriftModel) Parameter(dr.inference.model.Parameter)

Aggregations

ArbitraryBranchRates (dr.evomodel.branchratemodel.ArbitraryBranchRates)17 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)13 Parameter (dr.inference.model.Parameter)13 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)12 TreeDataLikelihood (dr.evomodel.treedatalikelihood.TreeDataLikelihood)11 StrictClockBranchRates (dr.evomodel.branchratemodel.StrictClockBranchRates)10 ArrayList (java.util.ArrayList)10 MultivariateElasticModel (dr.evomodel.continuous.MultivariateElasticModel)7 MatrixParameter (dr.inference.model.MatrixParameter)7 DiagonalMatrix (dr.inference.model.DiagonalMatrix)4 BeagleDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate)3 DataLikelihoodDelegate (dr.evomodel.treedatalikelihood.DataLikelihoodDelegate)3 ContinuousDataLikelihoodDelegate (dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate)3 TreeModel (dr.evomodel.tree.TreeModel)2 ArbitrarySubstitutionParameterBranchModel (dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel)1 BranchModel (dr.evomodel.branchmodel.BranchModel)1 AutoCorrelatedBranchRatesDistribution (dr.evomodel.branchratemodel.AutoCorrelatedBranchRatesDistribution)1 BranchSpecificFixedEffects (dr.evomodel.branchratemodel.BranchSpecificFixedEffects)1 LocalBranchRates (dr.evomodel.branchratemodel.LocalBranchRates)1 RelaxedDriftModel (dr.evomodel.branchratemodel.RelaxedDriftModel)1