Skip to content

Commit

Permalink
[ML] Fix potential use of unintialised value when minimising lowess r…
Browse files Browse the repository at this point in the history
…egression function (#2268)

If for any reason the extrapolation range for lowess regression returns zero then globalMinimize, to find the function
minimum, would be supplied an empty collection of points and fail. This would then lead to minimum returning a
uninitialised value for the minimum. This shouldn't normally happen in our usage of it, but we have seen the error
message associated with supplying an empty collection to globalMinimize in our QA suite.
  • Loading branch information
tveasey committed May 16, 2022
1 parent 1b1bd0a commit 9d1507c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
classification and regression models. (See {ml-pull}2259[#2259].)
* Fix edge case which could cause the model bounds to blow up after detecting seasonality.
(See {ml-pull}2261[#2261].)
* Fix cause of "Must provide points at which to evaluate function" log error training
classification and regression models. (See {ml-pull}2268[#2268].)

== {es} version 8.2.0

Expand Down
8 changes: 6 additions & 2 deletions include/maths/common/CLowessDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,17 @@ typename CLowess<N>::TDoubleDoublePr CLowess<N>::minimum() const {
double range{(xb - xa) / static_cast<double>(X.size())};
xa = std::max(xa, xmin - 0.5 * range);
xb = std::min(xb, xmin + 0.5 * range);
if (xa == xb) {
return {xmin, fmin};
}

double dx{2.0 * (xb - xa) / static_cast<double>(X.size())};
X.clear();
for (double x = xa; x < xb; x += dx) {
X.push_back(x);
}
double xcand;
double fcand;
double xcand{xmin};
double fcand{fmin};
CSolvers::globalMinimize(
X, [this](double x) -> double { return this->predict(x); }, xcand, fcand, fsd);

Expand Down

0 comments on commit 9d1507c

Please sign in to comment.