Search in sources :

Example 31 with TreeDataLikelihood

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

the class LoadingsGibbsOperatorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    // Get XML attributes
    double weight = xo.getDoubleAttribute(WEIGHT);
    boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
    int numThreads = xo.getAttribute(NUM_THREADS, 4);
    boolean multiThreaded = xo.getAttribute(MULTI_THREADED, false);
    boolean useNewMode = xo.getAttribute(MODE, false);
    // Get main objects
    LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
    // TODO The next 3 lines are not necessary, nor in XML rules
    MatrixParameterInterface loadings = null;
    if (xo.getChild(MatrixParameterInterface.class) != null) {
        loadings = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class);
    }
    // Get priors
    DistributionLikelihood prior = (DistributionLikelihood) xo.getChild(DistributionLikelihood.class);
    MomentDistributionModel prior2 = (MomentDistributionModel) xo.getChild(MomentDistributionModel.class);
    DistributionLikelihood cutoffPrior = null;
    if (xo.hasChildNamed(CUTOFF_PRIOR)) {
        cutoffPrior = (DistributionLikelihood) xo.getChild(CUTOFF_PRIOR).getChild(DistributionLikelihood.class);
    }
    DistributionLikelihood WorkingPrior = null;
    if (xo.getChild(WORKING_PRIOR) != null) {
        WorkingPrior = (DistributionLikelihood) xo.getChild(WORKING_PRIOR).getChild(DistributionLikelihood.class);
    }
    // Dispatch
    if (prior != null) {
        if (useNewMode) {
            final FactorAnalysisOperatorAdaptor adaptor;
            if (LFM != null) {
                adaptor = new FactorAnalysisOperatorAdaptor.SampledFactors(LFM);
            } else {
                IntegratedFactorAnalysisLikelihood integratedLikelihood = (IntegratedFactorAnalysisLikelihood) xo.getChild(IntegratedFactorAnalysisLikelihood.class);
                TreeDataLikelihood treeLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
                adaptor = new FactorAnalysisOperatorAdaptor.IntegratedFactors(integratedLikelihood, treeLikelihood);
            }
            NewLoadingsGibbsOperator.ConstrainedSampler sampler = NewLoadingsGibbsOperator.ConstrainedSampler.parse(xo.getAttribute(CONSTRAINT, NewLoadingsGibbsOperator.ConstrainedSampler.NONE.getName()));
            return new NewLoadingsGibbsOperator(adaptor, prior, weight, randomScan, WorkingPrior, multiThreaded, numThreads, sampler);
        } else {
            // return new LoadingsGibbsOperator(LFM, prior, weight, randomScan, WorkingPrior, multiThreaded, numThreads);
            return null;
        }
    } else {
        return new LoadingsGibbsTruncatedOperator(LFM, prior2, weight, randomScan, loadings, cutoffPrior);
    }
}
Also used : MatrixParameterInterface(dr.inference.model.MatrixParameterInterface) NewLoadingsGibbsOperator(dr.inference.operators.factorAnalysis.NewLoadingsGibbsOperator) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) FactorAnalysisOperatorAdaptor(dr.inference.operators.factorAnalysis.FactorAnalysisOperatorAdaptor) LatentFactorModel(dr.inference.model.LatentFactorModel) MomentDistributionModel(dr.inference.distribution.MomentDistributionModel) IntegratedFactorAnalysisLikelihood(dr.evomodel.treedatalikelihood.continuous.IntegratedFactorAnalysisLikelihood) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) LoadingsGibbsTruncatedOperator(dr.inference.operators.factorAnalysis.LoadingsGibbsTruncatedOperator)

Example 32 with TreeDataLikelihood

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

the class GibbsSampleMissingTraitsOperator method parseTreeTrait.

private static TreeTrait parseTreeTrait(XMLObject xo, String prefix) throws XMLParseException {
    TreeDataLikelihood treeLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
    String traitName = null;
    if (xo.hasAttribute(TRAIT_NAME)) {
        traitName = (String) xo.getAttribute(TRAIT_NAME);
    } else {
        TreeTrait[] traits = treeLikelihood.getTreeTraits();
        List<String> traitNames = matchedTraitNames(traits, prefix + ".");
        if (traitNames.size() == 1) {
            traitName = traitNames.get(0);
        }
    }
    TreeTrait treeTrait = treeLikelihood.getTreeTrait(traitName);
    if (treeTrait == null) {
        throw new XMLParseException("Unknown partially observed tree trait");
    }
    return treeTrait;
}
Also used : TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) TreeTrait(dr.evolution.tree.TreeTrait)

Example 33 with TreeDataLikelihood

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

the class ContinuousDataLikelihoodDelegateTest method testLikelihoodDiagonalOURelaxed.

public void testLikelihoodDiagonalOURelaxed() {
    System.out.println("\nTest Likelihood using Diagonal OU Relaxed:");
    // 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 })));
    DiagonalMatrix strengthOfSelectionMatrixParam = new DiagonalMatrix(new Parameter.Default(new double[] { 1.0, 100.0, 100.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("likelihoodDiagonalOURelaxed", dataLikelihood);
    // Conditional moments (preorder)
    testConditionalMoments(dataLikelihood, likelihoodDelegate);
    // Conditional simulations
    MathUtils.setSeed(17890826);
    double[] expectedTraits = new double[] { -1.0, 2.0, 0.0, 1.811803424441062, 0.6837595819961084, -1.0607909328094163, 0.5, 3.8623525502275142, 5.5, 2.0, 5.0, -8.0, 11.0, 1.0, -1.5, 1.0, 2.5, 4.0 };
    testConditionalSimulations(dataLikelihood, likelihoodDelegate, diffusionModel, dataModel, rootPrior, expectedTraits);
    // Fixed Root
    ContinuousDataLikelihoodDelegate likelihoodDelegateInf = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModel, rootPriorInf, rateTransformation, rateModel, true);
    TreeDataLikelihood dataLikelihoodInf = new TreeDataLikelihood(likelihoodDelegateInf, treeModel, rateModel);
    testLikelihood("likelihoodDiagonalOURelaxedInf", dataLikelihoodInf);
    testConditionalMoments(dataLikelihoodInf, likelihoodDelegateInf);
}
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 34 with TreeDataLikelihood

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

the class ContinuousDataLikelihoodDelegateTest method testLikelihoodFullNonSymmetricOU.

public void testLikelihoodFullNonSymmetricOU() {
    System.out.println("\nTest Likelihood using Full Non symmetric OU:");
    // 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 })));
    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.2, 100.0, 0.1 });
    strengthOfSelectionParameters[2] = new Parameter.Default(new double[] { 10.0, 0.1, 50.5 });
    MatrixParameter strengthOfSelectionMatrixParam = new MatrixParameter("strengthOfSelectionMatrix", strengthOfSelectionParameters);
    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("likelihoodFullNonSymmetricOU", 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("likelihoodFullNonSymmetricOUInf", dataLikelihoodInf);
    testConditionalMoments(dataLikelihoodInf, likelihoodDelegateInf);
}
Also used : MatrixParameter(dr.inference.model.MatrixParameter) 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) MatrixParameter(dr.inference.model.MatrixParameter) Parameter(dr.inference.model.Parameter)

Example 35 with TreeDataLikelihood

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

the class ContinuousDataLikelihoodDelegateTest method testLikelihoodFullIOU.

public void testLikelihoodFullIOU() {
    System.out.println("\nTest Likelihood using Full IOU:");
    // 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 })));
    Parameter[] strengthOfSelectionParameters = new Parameter[3];
    strengthOfSelectionParameters[0] = new Parameter.Default(new double[] { 0.5, 0.5, 0.0 });
    strengthOfSelectionParameters[1] = new Parameter.Default(new double[] { 0.2, 5, 0.1 });
    strengthOfSelectionParameters[2] = new Parameter.Default(new double[] { 0.0, 1.0, 10.0 });
    MatrixParameter strengthOfSelectionMatrixParam = new MatrixParameter("strengthOfSelectionMatrix", strengthOfSelectionParameters);
    DiffusionProcessDelegate diffusionProcessDelegate = new IntegratedOUDiffusionModelDelegate(treeModel, diffusionModel, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParam));
    // Rates
    ContinuousRateTransformation rateTransformation = new ContinuousRateTransformation.Default(treeModel, true, false);
    BranchRateModel rateModel = new DefaultBranchRateModel();
    // CDL
    ContinuousDataLikelihoodDelegate likelihoodDelegate = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModelIntegrated, rootPriorIntegrated, rateTransformation, rateModel, false);
    // Likelihood Computation
    TreeDataLikelihood dataLikelihood = new TreeDataLikelihood(likelihoodDelegate, treeModel, rateModel);
    testLikelihood("likelihoodFullIOU", dataLikelihood);
// Conditional moments (preorder)
// testConditionalMoments(dataLikelihood, likelihoodDelegate);
}
Also used : MatrixParameter(dr.inference.model.MatrixParameter) ArrayList(java.util.ArrayList) MultivariateElasticModel(dr.evomodel.continuous.MultivariateElasticModel) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) MatrixParameter(dr.inference.model.MatrixParameter) Parameter(dr.inference.model.Parameter)

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