| 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.evolution.tree.Tree; |
| 29 |
import dr.inference.model.DesignMatrix; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import no.uib.cipr.matrix.SymmTridiagMatrix; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class GMRFTestLikelihood extends GMRFSkyrideLikelihood { |
| 41 |
|
| 42 |
public GMRFTestLikelihood(Tree tree, Parameter popParameter, Parameter precParameter, Parameter lambda, Parameter beta, DesignMatrix design) { |
| 43 |
super(tree, popParameter, null, precParameter, lambda, beta, design, false, true); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
private Parameter intervalsParameter; |
| 48 |
private Parameter statsParameter; |
| 49 |
private Parameter betaParameter; |
| 50 |
|
| 51 |
public GMRFTestLikelihood(Parameter inPop, Parameter inPrec, Parameter inLambda, Parameter inBeta, DesignMatrix design, Parameter intervals, Parameter statParameter) { |
| 52 |
super(); |
| 53 |
popSizeParameter = inPop; |
| 54 |
precisionParameter = inPrec; |
| 55 |
lambdaParameter = inLambda; |
| 56 |
intervalsParameter = intervals; |
| 57 |
statsParameter = statParameter; |
| 58 |
betaParameter = inBeta; |
| 59 |
fieldLength = popSizeParameter.getDimension(); |
| 60 |
addVariable(popSizeParameter); |
| 61 |
addVariable(precisionParameter); |
| 62 |
addVariable(lambdaParameter); |
| 63 |
addVariable(intervalsParameter); |
| 64 |
addVariable(statsParameter); |
| 65 |
addVariable(betaParameter); |
| 66 |
|
| 67 |
setupGMRFWeights(); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
protected void storeState() { |
| 72 |
super.storeState(); |
| 73 |
System.arraycopy(coalescentIntervals, 0, storedCoalescentIntervals, 0, coalescentIntervals.length); |
| 74 |
System.arraycopy(sufficientStatistics, 0, storedSufficientStatistics, 0, sufficientStatistics.length); |
| 75 |
storedWeightMatrix = weightMatrix.copy(); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
protected void restoreState() { |
| 80 |
super.restoreState(); |
| 81 |
System.arraycopy(storedCoalescentIntervals, 0, coalescentIntervals, 0, storedCoalescentIntervals.length); |
| 82 |
System.arraycopy(storedSufficientStatistics, 0, sufficientStatistics, 0, storedSufficientStatistics.length); |
| 83 |
weightMatrix = storedWeightMatrix; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
public double calculateLogLikelihood() { |
| 88 |
return 0; |
| 89 |
} |
| 90 |
|
| 91 |
protected void setupGMRFWeights() { |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
coalescentIntervals = intervalsParameter.getParameterValues(); |
| 110 |
sufficientStatistics = statsParameter.getParameterValues(); |
| 111 |
storedCoalescentIntervals = new double[coalescentIntervals.length]; |
| 112 |
storedSufficientStatistics = new double[sufficientStatistics.length]; |
| 113 |
|
| 114 |
|
| 115 |
double[] offdiag = new double[fieldLength - 1]; |
| 116 |
double[] diag = new double[fieldLength]; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
for (int i = 0; i < fieldLength - 1; i++) { |
| 122 |
offdiag[i] = -2.0 / (coalescentIntervals[i] + coalescentIntervals[i + 1]); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
for (int i = 1; i < fieldLength - 1; i++) |
| 127 |
diag[i] = -(offdiag[i] + offdiag[i - 1]); |
| 128 |
|
| 129 |
|
| 130 |
diag[0] = -offdiag[0]; |
| 131 |
diag[fieldLength - 1] = -offdiag[fieldLength - 2]; |
| 132 |
|
| 133 |
|
| 134 |
weightMatrix = new SymmTridiagMatrix(diag, offdiag); |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
} |