Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * BirthDeathLikelihoodTest.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.BirthDeathGernhard08Model;
33 import dr.evomodel.speciation.SpeciationLikelihood;
34 import dr.evomodel.speciation.SpeciationModel;
35 import dr.evomodelxml.tree.TreeModelParser;
36 import dr.inference.model.Likelihood;
37 import dr.inference.model.Parameter;
38 import junit.framework.Test;
39 import junit.framework.TestCase;
40 import junit.framework.TestSuite;
41
42 /**
43 * Birth-Death tester.
44 *
45 * @author Alexei Drummond
46 * @version 1.0
47 */
48 public class BirthDeathLikelihoodTest extends TestCase {
49
50 static final String TL = "TL";
51 static final String TREE_HEIGHT = TreeModelParser.ROOT_HEIGHT;
52
53 private FlexibleTree tree;
54
55 public BirthDeathLikelihoodTest(String name) {
56 super(name);
57 }
58
59 public void setUp() throws Exception {
60 super.setUp();
61
62 NewickImporter importer = new NewickImporter("((1:1.0,2:1.0):1.0,3:2.0);");
63 tree = (FlexibleTree) importer.importTree(null);
64 }
65
66 public void testBirthDeathLikelihood() {
67
68 //birth rate
69 double b = 1.0;
70
71 //death rate
72 double d = 0.5;
73
74 // correct value for oriented trees
75 double correct = -3.534621219768513;
76
77 birthDeathLikelihoodTester(tree, b - d, d / b, correct);
78 }
79
80 private void birthDeathLikelihoodTester(
81 Tree tree, double birthRate, double deathRate, double logL) {
82
83 Parameter b = new Parameter.Default("b", birthRate, 0.0, Double.MAX_VALUE);
84 Parameter d = new Parameter.Default("d", deathRate, 0.0, Double.MAX_VALUE);
85
86 SpeciationModel speciationModel = new BirthDeathGernhard08Model(b, d, null, BirthDeathGernhard08Model.TreeType.ORIENTED,
87 Units.Type.YEARS);
88 Likelihood likelihood = new SpeciationLikelihood(tree, speciationModel, "bd.like");
89
90 assertEquals(logL, likelihood.getLogLikelihood(), 1e-14);
91 }
92
93 public static Test suite() {
94 return new TestSuite(BirthDeathLikelihoodTest.class);
95 }
96 }