| 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.coalescent; |
| 27 |
|
| 28 |
import dr.evomodel.tree.TreeModel; |
| 29 |
import dr.inference.model.Likelihood; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class ExponentialProductPosteriorMeansLikelihood extends Likelihood.Abstract { |
| 38 |
|
| 39 |
|
| 40 |
public final static boolean FIXED_TREE = false; |
| 41 |
public static final boolean DEBUG = false; |
| 42 |
|
| 43 |
private TreeModel treeModel; |
| 44 |
private double[] posteriorMeans; |
| 45 |
|
| 46 |
|
| 47 |
public ExponentialProductPosteriorMeansLikelihood(TreeModel treeModel, double[] posteriorMeans) { |
| 48 |
super(treeModel); |
| 49 |
this.treeModel = treeModel; |
| 50 |
this.posteriorMeans = posteriorMeans; |
| 51 |
} |
| 52 |
|
| 53 |
public double calculateLogLikelihood() { |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
double logPDF = 0.0; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
CoalescentTreeIntervalStatistic ctis = new CoalescentTreeIntervalStatistic(treeModel); |
| 62 |
int coalescentIntervalCounter = 0; |
| 63 |
|
| 64 |
if (DEBUG) { |
| 65 |
System.err.println("ExponentialProductPosteriorMeansLikelihood dimension: " + ctis.getDimension()); |
| 66 |
} |
| 67 |
|
| 68 |
for (int i = 0; i < ctis.getDimension(); i++) { |
| 69 |
|
| 70 |
int combinations = (int)ctis.getLineageCount(i)*((int)ctis.getLineageCount(i)-1)/2; |
| 71 |
double branchLength = ctis.getStatisticValue(i); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
if (ctis.getLineageCount(i) != 1) { |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
if (i == ctis.getDimension()-1) { |
| 84 |
|
| 85 |
|
| 86 |
double logContribution = -posteriorMeans[coalescentIntervalCounter] - combinations*branchLength*Math.exp(-posteriorMeans[coalescentIntervalCounter]); |
| 87 |
if (DEBUG) { |
| 88 |
System.err.println(i + ": " + logContribution); |
| 89 |
} |
| 90 |
logPDF += logContribution; |
| 91 |
|
| 92 |
} else if (ctis.getLineageCount(i) > ctis.getLineageCount(i+1)) { |
| 93 |
|
| 94 |
|
| 95 |
double logContribution = -posteriorMeans[coalescentIntervalCounter] - combinations*branchLength*Math.exp(-posteriorMeans[coalescentIntervalCounter]); |
| 96 |
if (DEBUG) { |
| 97 |
System.err.println(i + ": " + logContribution); |
| 98 |
} |
| 99 |
logPDF += logContribution; |
| 100 |
|
| 101 |
coalescentIntervalCounter++; |
| 102 |
} else { |
| 103 |
|
| 104 |
|
| 105 |
double logContribution = -combinations*branchLength*Math.exp(-posteriorMeans[coalescentIntervalCounter]); |
| 106 |
if (DEBUG) { |
| 107 |
System.err.println(i + ": " + logContribution); |
| 108 |
} |
| 109 |
logPDF += logContribution; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
return logPDF; |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
protected boolean getLikelihoodKnown() { |
| 127 |
return false; |
| 128 |
} |
| 129 |
|
| 130 |
} |