Skip to content

[Repo Assist] fix: remove CheckFunctionEpsilon from NelderMead stop criteria#377

Draft
github-actions[bot] wants to merge 2 commits intodeveloperfrom
repo-assist/fix-issue-260-neldermead-funcepsilon-20260418-9b2d683b2af60012
Draft

[Repo Assist] fix: remove CheckFunctionEpsilon from NelderMead stop criteria#377
github-actions[bot] wants to merge 2 commits intodeveloperfrom
repo-assist/fix-issue-260-neldermead-funcepsilon-20260418-9b2d683b2af60012

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant.

Summary

Fixes the premature termination bug in NelderMead.minimize when the objective function has negative or near-zero values.

Root cause: OptimizationStop.IsCriteria called CheckFunctionEpsilon on both fold and fnew. This check stops optimization whenever a function value is below MinFunctionEpsilon (default 1e-8). Since negative values are always below 1e-8, any function with a negative minimum caused early, incorrect termination.

Changes

src/FSharp.Stats/Optimization/OptimizationStop.fs

  • Removed two CheckFunctionEpsilon calls from IsCriteria.
    The check is appropriate for constrained positive-only methods but is wrong for Nelder-Mead, which is a derivative-free method for general real-valued functions.
    Correct convergence is already handled by CheckStationaryPoint and CheckIteration.

tests/FSharp.Stats.Tests/Optimization.fs

  • Updated the Powell's Singular Function (PSF) test to compare against the true minimum (0,0,0,0) instead of the previously hardcoded "stopped-too-early" values. The fixed optimizer now converges to x ≈ (3.8e-5, -3.8e-6, -2.8e-5, -2.8e-5) — much closer to the true optimum.
  • Added a new negative-minimum quadratic test (f(x) = x2 - 0.32x - 0.13, minimum at x=0.16, f(x*)≈-0.1556) that directly reproduces the bug from issue [Feature Request] Documentation of Nelder-Mead method #260. This test failed before the fix.

Note: The existing Fletcher test used MinFunctionEpsilon = 1e-24 as a workaround; this workaround remains valid (it just overrides the epsilon, which is now ignored by IsCriteria).

Test Status

Passed!  - Failed: 0, Passed: 1195, Skipped: 0, Total: 1195

All 1195 tests pass, including 8 NelderMead tests (2 new).

Closes #260

Generated by 🌈 Repo Assist, see workflow run.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

…riteria

The IsCriteria function in OptimizationStop.fs included two calls to
CheckFunctionEpsilon which stops optimization when the function value
drops below MinFunctionEpsilon (default 1e-8). This caused premature
termination for any function with a minimum near or below zero — including
all functions with negative optima.

Remove the two CheckFunctionEpsilon calls from IsCriteria. The check is
appropriate for constrained positive-only optimisation methods but is
incorrect for Nelder-Mead, which handles arbitrary real-valued functions.
The stationary-point and iteration-limit checks correctly handle convergence.

Update PSF test to compare against the true minimum (0,0,0,0) since the
optimizer now converges correctly. Add a new test for the quadratic function
from issue #260 that has a negative minimum at x=0.16, f(x)≈-0.1556.

Closes #260

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.87%. Comparing base (3533493) to head (aca47a6).
⚠️ Report is 185 commits behind head on developer.

Additional details and impacted files
@@              Coverage Diff              @@
##           developer     #377      +/-   ##
=============================================
+ Coverage      47.61%   47.87%   +0.25%     
=============================================
  Files            152      135      -17     
  Lines          16765    12920    -3845     
  Branches        2253     1709     -544     
=============================================
- Hits            7983     6185    -1798     
+ Misses          8097     6221    -1876     
+ Partials         685      514     -171     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Documentation of Nelder-Mead method

1 participant