argmin-rs / argmin

Numerical optimization in pure Rust
http://argmin-rs.org
Apache License 2.0
972 stars 76 forks source link

Add a simple example of Nelder-Mead usage. #359

Closed cjordan closed 1 year ago

cjordan commented 1 year ago

Hi,

Thanks for the effort that's been put into argmin. I've recently used the Nelder-Mead part successfully and it will be a great addition to my tool belt.

I felt the need to contribute a simple example, because over the last couple of years, I've tried a couple of times to use argmin, and the existing docs and examples were not clear enough for me. I wanted to use Nelder-Mead, but I (even still) didn't know what a Rosenbrock function is in the existing example (Wikipedia suggests that this is a sensible thing to test optimisation algs, but my lack of familiarity was intimidating). This PR contains another Nelder-Mead example, which demonstrates searching for a cubic polynomial's roots. It also shows how to extract the optimised parameter from the Executor result, which was not obvious to me from the existing docs or examples.

Please feel free to edit what I've provided, and I'm open to suggestions on making this better. My objective is to make what already is a well-polished library even more accessible, and allow people like myself to continue developing in Rust instead of having to write more code to access e.g. scipy optimize instead.

stefan-k commented 1 year ago

Hi @cjordan, thanks a lot for this PR!! Improvements of documentation and examples are very welcome, and I'm very thankful for the effort you put into this! :) Having good documentation to make argmin more accessible is very important to me, but it is also a very time-cosuming task and as such every help is highly appreciated!

I apologize for the very very late reply, unfortunately I've been rather busy over the past months and currently only have limited access to the internet (#360).

Right now I have time for a rough review and I hope I'll be able to give a more in-depth review at a later stage (if even necessary).

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (ae98919) 93.35% compared to head (3bfecc6) 93.35%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #359 +/- ## ======================================= Coverage 93.35% 93.35% ======================================= Files 117 117 Lines 18803 18803 ======================================= Hits 17554 17554 Misses 1249 1249 ``` | [Impacted Files](https://app.codecov.io/gh/argmin-rs/argmin/pull/359?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=argmin-rs) | Coverage Δ | | |---|---|---| | [...gmin/src/solver/gradientdescent/steepestdescent.rs](https://app.codecov.io/gh/argmin-rs/argmin/pull/359?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=argmin-rs#diff-YXJnbWluL3NyYy9zb2x2ZXIvZ3JhZGllbnRkZXNjZW50L3N0ZWVwZXN0ZGVzY2VudC5ycw==) | `95.04% <ø> (ø)` | | | [argmin/src/solver/neldermead/mod.rs](https://app.codecov.io/gh/argmin-rs/argmin/pull/359?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=argmin-rs#diff-YXJnbWluL3NyYy9zb2x2ZXIvbmVsZGVybWVhZC9tb2QucnM=) | `94.30% <ø> (ø)` | | | [argmin/src/solver/linesearch/backtracking.rs](https://app.codecov.io/gh/argmin-rs/argmin/pull/359?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=argmin-rs#diff-YXJnbWluL3NyYy9zb2x2ZXIvbGluZXNlYXJjaC9iYWNrdHJhY2tpbmcucnM=) | `99.05% <100.00%> (ø)` | | | [argmin/src/solver/linesearch/hagerzhang.rs](https://app.codecov.io/gh/argmin-rs/argmin/pull/359?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=argmin-rs#diff-YXJnbWluL3NyYy9zb2x2ZXIvbGluZXNlYXJjaC9oYWdlcnpoYW5nLnJz) | `73.89% <100.00%> (ø)` | | | [argmin/src/solver/linesearch/mod.rs](https://app.codecov.io/gh/argmin-rs/argmin/pull/359?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=argmin-rs#diff-YXJnbWluL3NyYy9zb2x2ZXIvbGluZXNlYXJjaC9tb2QucnM=) | `77.27% <100.00%> (ø)` | | | [argmin/src/solver/linesearch/morethuente.rs](https://app.codecov.io/gh/argmin-rs/argmin/pull/359?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=argmin-rs#diff-YXJnbWluL3NyYy9zb2x2ZXIvbGluZXNlYXJjaC9tb3JldGh1ZW50ZS5ycw==) | `86.60% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

cjordan commented 1 year ago

Hi @stefan-k, thanks for reviewing my PR, and I'm glad you find it useful. No worries about being late to reply; I understand the feeling of being busy!

I agree with all of your points, and I've now made a new commit. Feel free to squash the commits (as I like to do to appease my OCD), or let me know if you want me to do it.