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);
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations