Debian Codegraph @

src/test/dr/evomodel/speciation/BirthDeathSSLikelihoodTest.java

raw symbols SCIP
1 /*
2 * BirthDeathSSLikelihoodTest.java
3 *
4 * Copyright (C) 2002-2009 Alexei Drummond and Andrew Rambaut
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package test.dr.evomodel.speciation;
27
28 import dr.evolution.io.NewickImporter;
29 import dr.evolution.tree.FlexibleTree;
30 import dr.evolution.tree.Tree;
31 import dr.evolution.util.Units;
32 import dr.evomodel.speciation.BirthDeathSerialSamplingModel;
33 import dr.evomodel.speciation.SpeciationLikelihood;
34 import dr.evomodel.speciation.SpeciationModel;
35 import dr.inference.model.Likelihood;
36 import dr.inference.model.Variable;
37 import junit.framework.Test;
38 import junit.framework.TestCase;
39 import junit.framework.TestSuite;
40
41 /**
42 * YuleModel Tester.
43 *
44 * @author Alexei Drummond
45 * @version 1.0
46 * @since <pre>08/26/2007</pre>
47 */
48 public class BirthDeathSSLikelihoodTest extends TestCase {
49
50 private FlexibleTree tree;
51 private FlexibleTree tree2;
52
53 public BirthDeathSSLikelihoodTest(String name) {
54 super(name);
55 }
56
57 public void setUp() throws Exception {
58 super.setUp();
59
60 NewickImporter importer = new NewickImporter("((1:1.0,2:1.0):1.0,3:2.0);");
61 tree = (FlexibleTree) importer.importTree(null);
62
63 importer = new NewickImporter("((3 : 1.5, 4 : 0.5) : 1 , (1 : 2, 2 : 1) : 3);");
64 tree2 = (FlexibleTree) importer.importTree(null);
65 }
66
67 public void testBirthDeathLikelihoodBEAST2() {
68 System.out.println("RootHeight = " + tree2.getRootHeight());
69 Variable<Double> origin = new Variable.D("origin", 6.0);
70
71 final double birthRate = 2.0;
72 final double deathRate = 1.0;
73 final double psiRate = 0.5; // rate of sampling taxa through time
74 final double sampleProbability = 0.0; // the proportion of taxa sampled, default to fix to 0
75 final boolean hasFinalSample = false;
76 Variable<Double> b = new Variable.D("b", birthRate);
77 Variable<Double> d = new Variable.D("d", deathRate);
78 Variable<Double> psi = new Variable.D("psi", psiRate);
79 Variable<Double> p = new Variable.D("p", sampleProbability);
80 Variable<Double> r = new Variable.D("r", 0.0); // sampleBecomesNonInfectiousProb
81
82 SpeciationModel speciationModel = new BirthDeathSerialSamplingModel(b, d, psi, p, false, r, hasFinalSample, origin, Units.Type.YEARS);
83 Likelihood likelihood = new SpeciationLikelihood(tree2, speciationModel, "bdss.like");
84
85 assertEquals(-19.0198, likelihood.getLogLikelihood(), 1e-5);
86 }
87
88 final double birthRate = 1.0;
89 final double deathRate = 0.5;
90 final double p = 1.0;
91 final double psi = 0.0;
92
93 public void testBirthDeathLikelihoodP0() {
94 assertEquals(BirthDeathSerialSamplingModel.p0(birthRate, deathRate, p, psi, 1.0), 0.28236670080320814);
95 }
96
97 // public void testP1() {
98 // assertEquals(BirthDeathSerialSamplingModel.p1(birthRate, deathRate, p, psi, 1.0), 0.31236180503535266);
99 // }
100
101 // public void testPureBirthLikelihood() {
102 // likelihoodTester(tree, 1, 0, -2.8219461696520542);
103 // }
104
105 // public void testBirthDeathLikelihood() {
106 // likelihoodTester(tree, birthRate, deathRate, null, -4.633233508436623);
107 // }
108
109 public void testBirthDeathLikelihoodOrigin() {
110 System.out.println("RootHeight = " + tree.getRootHeight());
111 Variable<Double> origin = new Variable.D("origin", 50);
112 likelihoodTester(tree, birthRate, deathRate, origin, -29.529647743897872);
113 }
114
115 private void likelihoodTester(Tree tree, double birthRate, double deathRate, Variable<Double> origin, double logL) {
116
117 Variable<Double> b = new Variable.D("b", birthRate);
118 Variable<Double> d = new Variable.D("d", deathRate);
119 Variable<Double> psi = new Variable.D("psi", this.psi);
120 Variable<Double> p = new Variable.D("p", this.p);
121 Variable<Double> r = new Variable.D("r", 0.5);
122 Variable<Double> fTime = new Variable.D("time", 0.0);
123
124 SpeciationModel speciationModel = new BirthDeathSerialSamplingModel(b, d, psi, p, false, r, true, origin, Units.Type.YEARS);
125 Likelihood likelihood = new SpeciationLikelihood(tree, speciationModel, "bdss.like");
126
127 assertEquals(logL, likelihood.getLogLikelihood());
128 }
129
130 public static Test suite() {
131 return new TestSuite(BirthDeathSSLikelihoodTest.class);
132 }
133 }