Skip to content

Commit

Permalink
use abs to compare small value..
Browse files Browse the repository at this point in the history
  • Loading branch information
xji3 committed Dec 7, 2023
1 parent c81ca40 commit 8ea3451
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dr/evomodel/coalescent/smooth/SkyGlideLikelihood.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ private void updateIntervalGradient(double intervalStart, double intervalEnd, in
assert(slope != 0 || intercept != 0);
final double realSmall = MachineAccuracy.SQRT_EPSILON*(Math.abs(slope) + 1.0); // TODO: arbitrary magic bound
if (intervalStart != intervalEnd) {
final double slopeMultiplier = slope < realSmall ? Math.exp(-intercept) * (intervalStart * intervalStart - intervalEnd * intervalEnd) / 2
final double slopeMultiplier = Math.abs(slope) < realSmall ? Math.exp(-intercept) * (intervalStart * intervalStart - intervalEnd * intervalEnd) / 2
: Math.exp(-intercept) * ( (-intervalStart * Math.exp(-slope * intervalStart) + intervalEnd * Math.exp(-slope * intervalEnd))
- (Math.exp(-slope * intervalStart) - Math.exp(-slope * intervalEnd)) / slope) / slope;
final double interceptMultiplier = slope < realSmall ? (intervalEnd - intervalStart) * (-Math.exp(-intercept))
final double interceptMultiplier = Math.abs(slope) < realSmall ? (intervalEnd - intervalStart) * (-Math.exp(-intercept))
: Math.exp(-intercept) * (-Math.exp(-slope * intervalStart ) + Math.exp(-slope * intervalEnd )) / slope;

updateGridInterceptDerivativeWrtLogPopSize(gridIndex, gradient, lineageMultiplier * interceptMultiplier);
Expand Down

0 comments on commit 8ea3451

Please sign in to comment.