| 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 dr.evomodel.speciation; |
| 27 |
|
| 28 |
import dr.evolution.coalescent.DemographicFunction; |
| 29 |
import dr.evolution.tree.NodeRef; |
| 30 |
import dr.evomodel.coalescent.VDdemographicFunction; |
| 31 |
import dr.inference.distribution.ParametricDistributionModel; |
| 32 |
import dr.inference.model.CompoundModel; |
| 33 |
import dr.inference.model.Likelihood; |
| 34 |
import dr.inference.model.Parameter; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class SpeciesTreeSimplePrior extends Likelihood.Abstract { |
| 41 |
|
| 42 |
private final SpeciesTreeModel sTree; |
| 43 |
|
| 44 |
private final ParametricDistributionModel tips; |
| 45 |
private final Parameter sigma; |
| 46 |
private static final double d1 = (1 - Math.exp(-1)); |
| 47 |
private static final double f2 = Math.log(Math.sqrt(2*Math.PI)); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public SpeciesTreeSimplePrior(SpeciesTreeModel sTree, Parameter sigma, ParametricDistributionModel tipsPrior) { |
| 62 |
super(new CompoundModel("STprior")); |
| 63 |
this.sTree = sTree; |
| 64 |
this.sigma = sigma; |
| 65 |
this.tips = tipsPrior; |
| 66 |
|
| 67 |
final CompoundModel cm = (CompoundModel)this.getModel(); |
| 68 |
cm.addModel(tipsPrior); |
| 69 |
cm.addModel(sTree); |
| 70 |
} |
| 71 |
|
| 72 |
protected double calculateLogLikelihood() { |
| 73 |
double ll = 0; |
| 74 |
final NodeRef root = sTree.getRoot(); |
| 75 |
double l = sTree.getNodeHeight(root) + ((VDdemographicFunction)sTree.getNodeDemographic(root)).naturalLimit() ; |
| 76 |
|
| 77 |
for(int nn = 0; nn < sTree.getNodeCount(); ++nn) { |
| 78 |
final NodeRef n = sTree.getNode(nn); |
| 79 |
final DemographicFunction demog = sTree.getNodeDemographic(n); |
| 80 |
|
| 81 |
if( sTree.isExternal(n) ) { |
| 82 |
ll += tips.logPdf(demog.getDemographic(0)); |
| 83 |
} |
| 84 |
|
| 85 |
final double branch = sTree.isRoot(n) ? ((VDdemographicFunction)demog).naturalLimit() |
| 86 |
: sTree.getBranchLength(n); |
| 87 |
final double avg = branch/demog.getIntegral(0, branch); |
| 88 |
|
| 89 |
final double p = demog.getDemographic(branch); |
| 90 |
final double s = sigma.getParameterValue(0) * Math.sqrt((1 - Math.exp(-branch/l)) / d1); |
| 91 |
|
| 92 |
|
| 93 |
double z = p/avg; |
| 94 |
final double v2 = Math.log(z); |
| 95 |
final double v1 = v2 / s + s / 2; |
| 96 |
final double v = -Math.log(s) - f2 - v2 - v1*v1/2; |
| 97 |
ll += v; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
return ll; |
| 107 |
} |
| 108 |
|
| 109 |
protected boolean getLikelihoodKnown() { |
| 110 |
return false; |
| 111 |
} |
| 112 |
|
| 113 |
} |