Add Brent's method optimization algorithm#328
Merged
josevalim merged 4 commits intoelixir-nx:mainfrom Jan 11, 2026
Merged
Conversation
Implements Brent's method for scalar function minimization, combining golden section search with parabolic interpolation for faster convergence. Key features: - Pure defn implementation (JIT/GPU compatible) - ~3-5x fewer function evaluations than Golden Section - Same API pattern as GoldenSection.minimize/4 Also updates notebooks/optimize.livemd to present Brent as the recommended method with performance comparisons. Adds agents.md documenting best practices from José Valim's review feedback on PR elixir-nx#327 for future optimization algorithm contributors.
This reverts commit e9778a8.
josevalim
approved these changes
Jan 11, 2026
Contributor
|
@nyo16 can you please send a separate PR for agents.md? Thank you! |
Contributor
|
💚 💙 💜 💛 ❤️ |
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.
Summary
This PR adds Scholar.Optimize.Brent, implementing Brent's method for scalar function minimization. This is the second optimization algorithm following the Golden Section merge in #327, continuing the incremental approach discussed in #323.
Brent's method combines the reliability of golden section search with faster convergence from parabolic interpolation, making it the recommended choice for scalar optimization (as noted in https://docs.scipy.org/doc/scipy/tutorial/optimize.html).
Changes
Features
Performance Comparison
Example
alias Scholar.Optimize.Brent
fun = fn x -> Nx.pow(Nx.subtract(x, 3), 2) end
result = Brent.minimize(0.0, 5.0, fun)
Nx.to_number(result.x) # => 3.0
Nx.to_number(result.fun_evals) # => ~8 (vs ~45 for Golden Section)
Implementation Notes
Following the patterns established in #327 and @josevalim's feedback:
I also added agent.md with the learnings from the last 2 PRs. It really helping the models to follow better the best practices.
References