| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 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 |
|
| 69 |
double b = 1.0; |
| 70 |
|
| 71 |
|
| 72 |
double d = 0.5; |
| 73 |
|
| 74 |
|
| 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 |
} |