| 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.treedatalikelihood.continuous; |
| 27 |
|
| 28 |
import dr.evomodel.treedatalikelihood.continuous.cdi.ContinuousDiffusionIntegrator; |
| 29 |
import dr.evomodel.treedatalikelihood.continuous.cdi.PrecisionType; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public interface RootProcessDelegate { |
| 36 |
|
| 37 |
int getExtraPartialBufferCount(); |
| 38 |
|
| 39 |
int getExtraMatrixBufferCount(); |
| 40 |
|
| 41 |
void calculateRootLogLikelihood(ContinuousDiffusionIntegrator cdi, int rootIndex, final double[] logLike, |
| 42 |
boolean incrementOuterProducts); |
| 43 |
|
| 44 |
void setRootPartial(ContinuousDiffusionIntegrator cdi); |
| 45 |
|
| 46 |
double getPseudoObservations(); |
| 47 |
|
| 48 |
int getPriorBufferIndex(); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
abstract class Abstract implements RootProcessDelegate { |
| 53 |
|
| 54 |
protected final ConjugateRootTraitPrior prior; |
| 55 |
private final PrecisionType precisionType; |
| 56 |
private final int priorBufferIndex; |
| 57 |
private final int numTraits; |
| 58 |
|
| 59 |
public abstract double getPseudoObservations(); |
| 60 |
|
| 61 |
public Abstract(final ConjugateRootTraitPrior prior, |
| 62 |
final PrecisionType precisionType, int numTraits, |
| 63 |
int partialBufferCount, int matrixBufferCount) { |
| 64 |
this.prior = prior; |
| 65 |
this.precisionType = precisionType; |
| 66 |
this.numTraits = numTraits; |
| 67 |
|
| 68 |
this.priorBufferIndex = partialBufferCount; |
| 69 |
} |
| 70 |
|
| 71 |
@Override |
| 72 |
public int getExtraPartialBufferCount() { |
| 73 |
return 2; |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public int getExtraMatrixBufferCount() { |
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public int getPriorBufferIndex() { return priorBufferIndex; } |
| 83 |
|
| 84 |
@Override |
| 85 |
public void calculateRootLogLikelihood(ContinuousDiffusionIntegrator cdi, int rootBufferIndex, |
| 86 |
final double[] logLike, boolean incrementOuterProducts) { |
| 87 |
cdi.calculateRootLogLikelihood(rootBufferIndex, priorBufferIndex, logLike, incrementOuterProducts); |
| 88 |
} |
| 89 |
|
| 90 |
@Override |
| 91 |
public void setRootPartial(ContinuousDiffusionIntegrator cdi) { |
| 92 |
double[] mean = prior.getMean(); |
| 93 |
final int dimTrait = mean.length; |
| 94 |
|
| 95 |
final int length = dimTrait + precisionType.getMatrixLength(dimTrait); |
| 96 |
double[] partial = new double[length * numTraits]; |
| 97 |
|
| 98 |
int offset = 0; |
| 99 |
for (int trait = 0; trait < numTraits; ++trait) { |
| 100 |
System.arraycopy(mean, 0, partial, offset, dimTrait); |
| 101 |
|
| 102 |
final double precision = getPseudoObservations(); |
| 103 |
for (int i = 0; i < dimTrait; ++i) { |
| 104 |
precisionType.fillPrecisionInPartials(partial, offset, i, precision, dimTrait); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
offset += length; |
| 109 |
} |
| 110 |
|
| 111 |
cdi.setPostOrderPartial(priorBufferIndex, partial); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
class Fixed extends Abstract { |
| 116 |
|
| 117 |
public Fixed(ConjugateRootTraitPrior prior, PrecisionType precisionType, |
| 118 |
int numTraits, int partialBufferCount, int matrixBufferCount) { |
| 119 |
super(prior, precisionType, numTraits, partialBufferCount, matrixBufferCount); |
| 120 |
} |
| 121 |
|
| 122 |
@Override |
| 123 |
public double getPseudoObservations() { |
| 124 |
return Double.POSITIVE_INFINITY; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
class FullyConjugate extends Abstract { |
| 132 |
|
| 133 |
public FullyConjugate(ConjugateRootTraitPrior prior, PrecisionType precisionType, |
| 134 |
int numTraits, int partialBufferCount, int matrixBufferCount) { |
| 135 |
super(prior, precisionType, numTraits, partialBufferCount, matrixBufferCount); |
| 136 |
} |
| 137 |
|
| 138 |
@Override |
| 139 |
public double getPseudoObservations() { |
| 140 |
return prior.getPseudoObservations(); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
} |
| 146 |
} |