Skip to content

Commit

Permalink
Take expiry into account for approximation interval
Browse files Browse the repository at this point in the history
When solving for an interval over which to take an approximation, we take the expiry of the dynamics
to be approximated into account. In the case when no solution is found, we should still take expiry into account.

This is especially important when that expiry is much shorter than the typical approximation interval.
In this case, we can often choose the full expiry as the approximation interval without reaching our maximum error tolerance,
resulting in a NoBracketingException from the solver. In this case, we should choose the expiry, not the maximum approximation interval,
to be consistent with the time range we searched.
  • Loading branch information
David Legg authored and mattdailis committed Mar 1, 2024
1 parent 06e840c commit c783a86
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,26 @@ public static <D extends Dynamics<?, D>> Function<Expiring<D>, Duration> byBound
exp.data(),
t,
maximumError));
var effectiveMinSamplePeriod = Duration.min(e, minimumSamplePeriod);
var effectiveMaxSamplePeriod = Duration.min(e, maximumSamplePeriod);

try {
double intervalSize = solver.solve(
100,
errorFn,
Duration.min(e, minimumSamplePeriod).ratioOver(SECOND),
Duration.min(e, maximumSamplePeriod).ratioOver(SECOND));
effectiveMinSamplePeriod.ratioOver(SECOND),
effectiveMaxSamplePeriod.ratioOver(SECOND));
return Duration.roundNearest(intervalSize, SECOND);
} catch (NoBracketingException x) {
if (errorFn.value(minimumSamplePeriod.ratioOver(SECOND)) > 0) {
// maximum error > estimated error, best case
return maximumSamplePeriod;
return effectiveMaxSamplePeriod;
} else {
// maximum error < estimated error, worst case
return minimumSamplePeriod;
return effectiveMinSamplePeriod;
}
} catch (TooManyEvaluationsException | NumberIsTooLargeException x) {
return minimumSamplePeriod;
return effectiveMinSamplePeriod;
}
};
}
Expand Down

0 comments on commit c783a86

Please sign in to comment.