| 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.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 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 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; |
| 74 |
final double sampleProbability = 0.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); |
| 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 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 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 |
} |