use of beast.evolution.substitutionmodel.BinaryCovarion in project beast2 by CompEvol.
the class BinaryCovarionModelTest method doWithUnEqualHFreqs.
private void doWithUnEqualHFreqs(String mode) {
Frequencies dummyFreqs = new Frequencies();
dummyFreqs.initByName("frequencies", "0.25 0.25 0.25 0.25", "estimate", false);
BinaryCovarion substModel;
double d = 0.05 + Randomizer.nextDouble() * 0.9;
RealParameter hfrequencies = new RealParameter(new Double[] { d, 1.0 - d });
d = 0.05 + Randomizer.nextDouble() * 0.9;
RealParameter vfrequencies = new RealParameter(new Double[] { d, 1.0 - d });
substModel = new BinaryCovarion();
substModel.initByName("frequencies", dummyFreqs, "hfrequencies", hfrequencies, /* [f0, f1] */
"vfrequencies", vfrequencies, /* [p0, p1] */
"alpha", "0.01", "switchRate", "0.1", // "eigenSystem", "beast.evolution.substitutionmodel.RobustEigenSystem",
"mode", mode);
double[] matrix = new double[16];
substModel.getTransitionProbabilities(null, 1000, 0, 1.0, matrix);
double[] baseFreqs = new double[] { (vfrequencies.getValue(0) * hfrequencies.getValue(0)), (vfrequencies.getValue(1) * hfrequencies.getValue(0)), (vfrequencies.getValue(0) * hfrequencies.getValue(1)), (vfrequencies.getValue(1) * hfrequencies.getValue(1)) };
System.err.println("Expected: " + Arrays.toString(baseFreqs));
System.err.println("Calculat: " + Arrays.toString(matrix));
for (int j = 0; j < 4; j++) {
assertEquals(baseFreqs[j], matrix[j], 1e-3);
}
}
use of beast.evolution.substitutionmodel.BinaryCovarion in project beast2 by CompEvol.
the class TreeLikelihoodTest method testBinaryCovarionLikelihood.
@Test
public void testBinaryCovarionLikelihood() throws Exception {
Alignment data = BEASTTestCase.getCovarionAlignment();
Tree tree = BEASTTestCase.getTree(data, "((English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):1.5793160946109988,(Spanish:0.11078392189606047,(Italian:0.10119772534558173,French:0.10119772534558173):0.009586196550478737):1.6959656445951337)");
RealParameter alpha = new RealParameter("0.284");
RealParameter switchRate = new RealParameter("0.829");
RealParameter frequencies = new RealParameter("0.683 0.317");
RealParameter hfrequencies = new RealParameter("0.5 0.5");
BinaryCovarion covarion = new BinaryCovarion();
covarion.initByName("alpha", alpha, "switchRate", switchRate, "vfrequencies", frequencies, "hfrequencies", hfrequencies);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", covarion);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
// beast1 xml gives -1730.5363
assertEquals(logP, -1730.53631739, BEASTTestCase.PRECISION);
}
use of beast.evolution.substitutionmodel.BinaryCovarion in project beast2 by CompEvol.
the class BinaryCovarionModelTest method doWithEqualHFreqs.
private void doWithEqualHFreqs(String mode) {
Frequencies dummyFreqs = new Frequencies();
dummyFreqs.initByName("frequencies", "0.25 0.25 0.25 0.25", "estimate", false);
BinaryCovarion substModel;
RealParameter hfrequencies = new RealParameter(new Double[] { 0.5, 0.5 });
double d = Randomizer.nextDouble();
RealParameter vfrequencies = new RealParameter(new Double[] { d, 1.0 - d });
substModel = new BinaryCovarion();
substModel.initByName("frequencies", dummyFreqs, "hfrequencies", hfrequencies, /* [f0, f1] */
"vfrequencies", vfrequencies, /* [p0, p1] */
"alpha", "0.01", "switchRate", "0.1", "mode", mode);
double[] matrix = new double[16];
substModel.getTransitionProbabilities(null, 100, 0, 1.0, matrix);
double EPSILON = 1e-10;
assertEquals(vfrequencies.getValue(0) * hfrequencies.getValue(0), matrix[0], EPSILON);
assertEquals(vfrequencies.getValue(1) * hfrequencies.getValue(0), matrix[1], EPSILON);
assertEquals(vfrequencies.getValue(0) * hfrequencies.getValue(1), matrix[2], EPSILON);
assertEquals(vfrequencies.getValue(1) * hfrequencies.getValue(1), matrix[3], EPSILON);
}
use of beast.evolution.substitutionmodel.BinaryCovarion in project beast2 by CompEvol.
the class BinaryCovarionModelTest method doWithTufflySteel.
private void doWithTufflySteel() {
Frequencies dummyFreqs = new Frequencies();
dummyFreqs.initByName("frequencies", "0.25 0.25 0.25 0.25", "estimate", false);
BinaryCovarion substModel;
double d = 0.05 + Randomizer.nextDouble() * 0.9;
RealParameter vfrequencies = new RealParameter(new Double[] { d, 1.0 - d });
RealParameter switchrate = new RealParameter(new Double[] { Randomizer.nextDouble(), Randomizer.nextDouble() });
substModel = new BinaryCovarion();
substModel.initByName("frequencies", dummyFreqs, "vfrequencies", vfrequencies, /* [p0, p1] */
"alpha", "0.01", "switchRate", switchrate, // "eigenSystem", "beast.evolution.substitutionmodel.RobustEigenSystem",
"mode", "TUFFLEYSTEEL");
double[] matrix = new double[16];
substModel.getTransitionProbabilities(null, 1000, 0, 1.0, matrix);
double h0 = switchrate.getValue(1) / (switchrate.getValue(0) + switchrate.getValue(1));
double h1 = switchrate.getValue(0) / (switchrate.getValue(0) + switchrate.getValue(1));
double[] baseFreqs = new double[] { vfrequencies.getValue(0) * h0, vfrequencies.getValue(1) * h0, vfrequencies.getValue(0) * h1, vfrequencies.getValue(1) * h1 };
System.err.println("Expected: " + Arrays.toString(baseFreqs));
System.err.println("Calculat: " + Arrays.toString(matrix));
for (int j = 0; j < 4; j++) {
assertEquals(baseFreqs[j], matrix[j], 1e-3);
}
}
Aggregations