use of dr.evomodel.continuous.MultivariateElasticModel 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);
}
use of dr.evomodel.continuous.MultivariateElasticModel in project beast-mcmc by beast-dev.
the class RepeatedMeasureFactorTest method testLikelihoodOU.
public void testLikelihoodOU() {
System.out.println("\nTest Likelihood using full 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 })));
optimalTraitsModels.add(new StrictClockBranchRates(new Parameter.Default("rate.4", new double[] { 10.0 })));
optimalTraitsModels.add(new StrictClockBranchRates(new Parameter.Default("rate.5", new double[] { 20.0 })));
optimalTraitsModels.add(new StrictClockBranchRates(new Parameter.Default("rate.6", new double[] { -20.0 })));
Parameter[] strengthOfSelectionParameters = new Parameter[6];
strengthOfSelectionParameters[0] = new Parameter.Default(new double[] { 1.0, 0.1, 0.0, 0.0, 0.5, 2.0 });
strengthOfSelectionParameters[1] = new Parameter.Default(new double[] { 0.1, 10., 0.0, 0.0, 0.0, 0.0 });
strengthOfSelectionParameters[2] = new Parameter.Default(new double[] { 0.0, 0.0, 20., 0.3, 0.0, 0.0 });
strengthOfSelectionParameters[3] = new Parameter.Default(new double[] { 0.0, 0.0, 0.3, 30., 3.0, 0.0 });
strengthOfSelectionParameters[4] = new Parameter.Default(new double[] { 1.0, 0.0, 0.0, 3.0, 40., 0.0 });
strengthOfSelectionParameters[5] = new Parameter.Default(new double[] { 0.0, 0.0, 0.5, 0.0, 0.0, 50. });
MatrixParameter strengthOfSelectionMatrixParam = new MatrixParameter("strengthOfSelectionMatrix", strengthOfSelectionParameters);
DiffusionProcessDelegate diffusionProcessDelegate = new OUDiffusionModelDelegate(treeModel, diffusionModel, optimalTraitsModels, new MultivariateElasticModel(strengthOfSelectionMatrixParam));
// Rates
ContinuousRateTransformation rateTransformation = new ContinuousRateTransformation.Default(treeModel, false, false);
BranchRateModel rateModel = new DefaultBranchRateModel();
// // Factor Model //// *****************************************************************************************
// CDL
ContinuousDataLikelihoodDelegate likelihoodDelegateFactors = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModelFactor, rootPrior, rateTransformation, rateModel, true);
dataModelFactor.setLikelihoodDelegate(likelihoodDelegateFactors);
// Likelihood Computation
TreeDataLikelihood dataLikelihoodFactors = new TreeDataLikelihood(likelihoodDelegateFactors, treeModel, rateModel);
double logDatumLikelihoodFactor = getLogDatumLikelihood(dataModelFactor);
double likelihoodFactorData = dataLikelihoodFactors.getLogLikelihood();
double likelihoodFactorDiffusion = dataModelFactor.getLogLikelihood();
assertEquals("likelihoodOUFactor", format.format(logDatumLikelihoodFactor), format.format(likelihoodFactorData + likelihoodFactorDiffusion));
System.out.println("likelihoodOUFactor: " + format.format(logDatumLikelihoodFactor));
// Simulation
MathUtils.setSeed(17890826);
double[] traitsFactors = getConditionalSimulations(dataLikelihoodFactors, likelihoodDelegateFactors, diffusionModel, dataModelFactor, rootPrior, treeModel, rateTransformation);
System.err.println(new Vector(traitsFactors));
// // Repeated Measures //// ************************************************************************************
// CDL
ContinuousDataLikelihoodDelegate likelihoodDelegateRepMea = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModelRepeatedMeasures, rootPrior, rateTransformation, rateModel, true);
// Likelihood Computation
TreeDataLikelihood dataLikelihoodRepMea = new TreeDataLikelihood(likelihoodDelegateRepMea, treeModel, rateModel);
double logDatumLikelihoodRepMea = getLogDatumLikelihood(dataLikelihoodRepMea);
double likelihoodRepMeaDiffusion = dataLikelihoodRepMea.getLogLikelihood();
assertEquals("likelihoodOURepMea", format.format(logDatumLikelihoodRepMea), format.format(likelihoodRepMeaDiffusion));
System.out.println("likelihoodOURepMea: " + format.format(logDatumLikelihoodRepMea));
// Simulation
MathUtils.setSeed(17890826);
double[] traitsRepMea = getConditionalSimulations(dataLikelihoodRepMea, likelihoodDelegateRepMea, diffusionModel, dataModelRepeatedMeasures, rootPrior, treeModel, rateTransformation);
System.err.println(new Vector(traitsRepMea));
// // Equal ? //// **********************************************************************************************
assertEquals("likelihoodOURepFactor", format.format(likelihoodFactorData + likelihoodFactorDiffusion), format.format(likelihoodRepMeaDiffusion));
for (int i = 0; i < traitsFactors.length; i++) {
assertEquals(format.format(traitsRepMea[i]), format.format(traitsFactors[i]));
}
// // Repeated Measures Full //// *******************************************************************************
// CDL
ContinuousDataLikelihoodDelegate likelihoodDelegateRepMeaFull = new ContinuousDataLikelihoodDelegate(treeModel, diffusionProcessDelegate, dataModelRepeatedMeasuresFull, rootPrior, rateTransformation, rateModel, true);
// Likelihood Computation
TreeDataLikelihood dataLikelihoodRepMeaFull = new TreeDataLikelihood(likelihoodDelegateRepMeaFull, treeModel, rateModel);
double logDatumLikelihoodRepMeaFull = getLogDatumLikelihood(dataLikelihoodRepMeaFull);
double likelihoodRepMeaDiffusionFull = dataLikelihoodRepMeaFull.getLogLikelihood();
assertEquals("likelihoodBMRepMea", format.format(logDatumLikelihoodRepMeaFull), format.format(likelihoodRepMeaDiffusionFull));
System.out.println("likelihoodBMRepMeaFull: " + format.format(logDatumLikelihoodRepMeaFull));
}
use of dr.evomodel.continuous.MultivariateElasticModel in project beast-mcmc by beast-dev.
the class ContinuousDataLikelihoodDelegateTest method testLikelihoodFullOU.
public void testLikelihoodFullOU() {
System.out.println("\nTest Likelihood using Full 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.2, 0.0 });
strengthOfSelectionParameters[1] = new Parameter.Default(new double[] { 0.2, 100.0, 0.1 });
strengthOfSelectionParameters[2] = new Parameter.Default(new double[] { 0.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("likelihoodFullOU", dataLikelihood);
// Conditional moments (preorder)
testConditionalMoments(dataLikelihood, likelihoodDelegate);
// Conditional simulations
MathUtils.setSeed(17890826);
double[] expectedTraits = new double[] { -1.0, 2.0, 0.0, 1.0427958776637916, 2.060317467842193, 0.5916377446549433, 0.5, 2.07249828895442, 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("likelihoodFullOUInf", dataLikelihoodInf);
testConditionalMoments(dataLikelihoodInf, likelihoodDelegateInf);
}
use of dr.evomodel.continuous.MultivariateElasticModel in project beast-mcmc by beast-dev.
the class ContinuousDataLikelihoodDelegateTest method testLikelihoodFullOURelaxedFactor.
public void testLikelihoodFullOURelaxedFactor() {
System.out.println("\nTest Likelihood using full Relaxed 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.15 });
strengthOfSelectionParameters[1] = new Parameter.Default(new double[] { 0.15, 25.5 });
MatrixParameter strengthOfSelectionMatrixParam = new MatrixParameter("strengthOfSelectionMatrix", strengthOfSelectionParameters);
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("likelihoodFullRelaxedOUFactor", dataModelFactor, dataLikelihoodFactors);
// Conditional simulations
MathUtils.setSeed(17890826);
double[] expectedTraits = new double[] { 0.6074917696668031, 1.4240248941610945, 0.5818653246406664, 1.545237778993696, 0.7248840308905077, 1.4623057820376757, 1.0961030597302799, 1.603694717986661, 0.44280937767720896, 1.5374906898020686, 0.920698984735896, 1.6011019734876784 };
testConditionalSimulations(dataLikelihoodFactors, likelihoodDelegateFactors, diffusionModelFactor, dataModelFactor, rootPriorFactor, expectedTraits);
}
Aggregations