Conversation
## Summary Fixes elastic#2772, where an uncertain fitted trend could dominate a long forecast and produce implausible curvature, including values outside a percentage metric's natural range. ## Mathematical rationale The trend component returns a polynomial regression prediction `f(x)` and its covariance-derived forecast variance. Previously, a forecast evaluated the fitted polynomial directly at every future time. This means a small but poorly determined quadratic coefficient is multiplied by `x^2`; over a long horizon that term can become much larger than the local signal even when the model is highly uncertain about it. The existing prediction-horizon guard does not cover this case: the requested duration can be operationally reasonable while the selected trend is still statistically unreliable to extrapolate. The fix keeps the model's near-term prediction but attenuates its *change from the first forecast point* according to the fraction of variance explained by the fitted trend: ```text w(t) = V_trend / (V_trend + V_extrapolation(t)) y_fixed(t) = f(t0) + w(t) * (f(t) - f(t0)) ``` Here `t0` is the first forecast time, `V_trend` is the component's long-term variance, and `V_extrapolation(t)` is the additional uncertainty incurred by projecting the fitted polynomial from the regression origin to `t`. Thus `w(t)` is close to one when the trend is reliable, preserving the original prediction; it falls toward zero when extrapolation uncertainty dominates, smoothly anchoring the forecast at the boundary instead of allowing an uncertain high-order term to diverge. This uses no new persisted state, settings, metric bounds, or customer-wide runtime cost. The covariance calculation must use the regression basis. The trend model is parameterized at its regression origin, so the variance of the change `f(t) - f(t0)` uses the basis delta: ```text [0, t - t0, t^2 - t0^2] ``` Using `[1, t, t^2]` instead incorrectly includes the intercept and computes the variance of an absolute prediction rather than the extrapolated change. This PR corrects that basis. ## Behaviour and coverage - Exact zero extrapolation variance retains the original trend prediction (`w = 1`); this prevents a regression for deterministic affine trends. - Invalid or negative numerical variances take the conservative anchored fallback. - The forecast remains continuous at the first prediction point. - Added tests cover the restored elastic#2772 state, prefix continuity, affine trends, and exact zero-uncertainty trends. This targets the intended observability workload: ordinary trend forecasts remain unchanged when their extrapolation is well supported, while temporary changes and weakly identified curvature cannot dominate a long-horizon forecast. (cherry picked from commit aca6006) # Conflicts: # lib/maths/time_series/unittest/CTrendComponentTest.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport
This will backport the following commits from
mainto8.19:Questions ?
Please refer to the Backport tool documentation