From c783a868ab57e138a9fc244e8b64e10ac05f04ad Mon Sep 17 00:00:00 2001 From: David Legg Date: Mon, 5 Feb 2024 17:39:13 -0800 Subject: [PATCH] Take expiry into account for approximation interval 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. --- .../modeling/black_box/IntervalFunctions.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/black_box/IntervalFunctions.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/black_box/IntervalFunctions.java index 3024d654d9..6e91504987 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/black_box/IntervalFunctions.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/black_box/IntervalFunctions.java @@ -59,23 +59,26 @@ public static > Function, 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; } }; }