use of dr.evolution.coalescent.DemographicFunction in project beast-mcmc by beast-dev.
the class TransmissionLikelihood method calculateLogLikelihood.
/**
* Calculates the log likelihood of this set of coalescent intervals,
* given a demographic model.
*/
public double calculateLogLikelihood() {
makeDirty();
setupHosts();
for (int i = 0; i < hostCount; i++) {
intervals[i].resetEvents();
donorSize[i] = -1;
}
try {
setupIntervals(virusTree.getRoot());
} catch (IncompatibleException re) {
// register the compatibility failure
return Double.NEGATIVE_INFINITY;
}
for (int i = 0; i < hostCount; i++) {
donorSize[i] = -1;
}
DemographicFunction demoFunction = sourceDemographic.getDemographicFunction();
double logL = Coalescent.calculateLogLikelihood(intervals[0], demoFunction);
for (int i = 1; i < hostCount; i++) {
double ds = getDonorSize(i);
demoFunction = transmissionModel.getDemographicFunction(transmissionTime[i], ds, i);
logL += Coalescent.calculateLogLikelihood(intervals[i], demoFunction);
}
return logL;
}
use of dr.evolution.coalescent.DemographicFunction in project beast-mcmc by beast-dev.
the class TransmissionLikelihood method getDonorSize.
private double getDonorSize(int host) {
if (donorSize[host] > 0.0) {
return donorSize[host];
}
DemographicFunction demoFunction;
if (donorHost[host] == 0) {
demoFunction = sourceDemographic.getDemographicFunction();
} else {
double ds = getDonorSize(donorHost[host]);
demoFunction = transmissionModel.getDemographicFunction(transmissionTime[host], ds, host);
}
donorSize[host] = demoFunction.getDemographic(transmissionTime[host]);
return donorSize[host];
}
Aggregations