Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@imohiyoko
Copy link

This PR addresses issue #483 by introducing a new sub-package optimize/scalar and implementing Brent's method for finding the local minimum of a univariate function.

Summary of Changes

  • Created gonum/optimize/scalar package.
  • Implemented BrentMin, a derivative-free minimization algorithm combining the golden section search and successive parabolic interpolation.
  • The implementation is a direct port of Netlib's fmin.f (by Richard Brent) to ensure numerical stability and correctness.
  • Added comprehensive tests in brent_min_test.go.

Design Decisions

  • File Naming: I chose brent_min.go (instead of just brent.go) to explicitly distinguish it from Brent's root-finding method (Zeroin). This leaves room to add the root-finding algorithm (discussed in optimize, all: Re-use of the optimize implementation #925) as brent_root.go in the same package in the future.
  • API: The function signature accepts a Settings struct for fine-grained control (tolerance, max iterations) and returns a Result struct with metadata (status, iteration count), following the convention of the optimize package.

Reference


Note for reviewers:
I am a university student studying numerical analysis, and this is my first contribution to Gonum (and OSS in general). I have tried to follow the project's conventions, but I would greatly appreciate any feedback or guidance if there are areas for improvement.

Copy link
Member

@kortschak kortschak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review only.

const c = 0.3819660112501051517954131656343618822796908201942371

// Default settings
tol := math.Sqrt(epsilon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a const.

settings *Settings
wantX float64
wantStatus Status
distTol float64 // 許容する x の誤差 (wantX との距離)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in English please.

imohiyoko and others added 4 commits December 21, 2025 18:28
Thanks, applied

Co-authored-by: Dan Kortschak <[email protected]>
Thanks, applied

Co-authored-by: Dan Kortschak <[email protected]>
Update epsilon to use the hexadecimal floating-point literal 0x1p-52.
Define the default tolerance (sqrt of epsilon) as a constant 0x1p-26 instead of calculating it at runtime.
- Translate Japanese comments in tests to English.
- Use hexadecimal floating-point literals for epsilon.
- Clarify documentation for default MaxIterations.
@imohiyoko imohiyoko requested a review from kortschak December 21, 2025 10:18
username and others added 21 commits December 23, 2025 13:49
- Group constants and state variables (e, d) into blocks.
- Simplify numeric expressions and literals (e.g., use /2 instead of *0.5).
- Use hexadecimal floating-point literals for epsilon.
- Prepare Status type for stringer and remove manual String method.
Updated the implementation to align with Gonum coding standards:
- Improved constant/variable grouping and numeric expressions.
- Integrated stringer for Status type.
- Refactored tests by hoisting cases and simplifying identifiers.
@imohiyoko imohiyoko requested a review from kortschak December 23, 2025 08:18
@imohiyoko imohiyoko requested a review from kortschak December 24, 2025 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants