public static double calculateLogLikelihood(IntervalList intervals,DemographicFunction demographicFunction,double threshold){
  double logL=0.0;
  double startTime=0.0;
  final int n=intervals.getIntervalCount();
  for (int i=0; i < n; i++) {
    final double duration=intervals.getInterval(i);
    final double finishTime=startTime + duration;
    final double intervalArea=demographicFunction.getIntegral(startTime,finishTime);
    if (intervalArea == 0 && duration != 0) {
      return Double.NEGATIVE_INFINITY;
    }
    final int lineageCount=intervals.getLineageCount(i);
    final double kChoose2=Binomial.choose2(lineageCount);
    logL+=-kChoose2 * intervalArea;
    if (intervals.getIntervalType(i) == IntervalType.COALESCENT) {
      final double demographicAtCoalPoint=demographicFunction.getDemographic(finishTime);
      if (duration == 0.0 || demographicAtCoalPoint * (intervalArea / duration) >= threshold) {
        logL-=Math.log(demographicAtCoalPoint);
      }
 else {
        return Double.NEGATIVE_INFINITY;
      }
    }
    startTime=finishTime;
  }
  return logL;
}

public static double calculateLogLikelihood ( IntervalList intervals , DemographicFunction demographicFunction , double threshold ) { double logL = 0.0 ; double startTime = 0.0 ; final int n = intervals . getIntervalCount ( ) ; for ( int i = 0 ; i < n ; i ++ ) { final double duration = intervals . getInterval ( i ) ; final double finishTime = startTime + duration ; final double intervalArea = demographicFunction . getIntegral ( startTime , finishTime ) ; if ( intervalArea == 0 && duration != 0 ) { return Double . NEGATIVE_INFINITY ; } final int lineageCount = intervals . getLineageCount ( i ) ; final double kChoose2 = Binomial . choose2 ( lineageCount ) ; logL += - kChoose2 * intervalArea ; if ( intervals . getIntervalType ( i ) == IntervalType . COALESCENT ) { final double demographicAtCoalPoint = demographicFunction . getDemographic ( finishTime ) ; if ( duration == 0.0 || demographicAtCoalPoint * ( intervalArea / duration ) >= threshold ) { logL -= Math . log ( demographicAtCoalPoint ) ; } else { return Double . NEGATIVE_INFINITY ; } } startTime = finishTime ; } return logL ; }
calculates the log likelihood of this set of coalescent intervals , given a demographic model .
