Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trait f64 f32 for 1d inverse to ArgminInv #346

Merged
merged 1 commit into from
May 5, 2023

Conversation

sdrap
Copy link
Contributor

@sdrap sdrap commented May 4, 2023

I tried to implement the f64/f32 standard inverse for the ArgminInv (modification in the implementation of inv for ndarray).
I also added a test for it.

For unknown compilation reasons on my machine (admittedly weird linux conf), I could not run the test nor use the library locally to check if that works. I will have to look later into it.

I am also not sure if this is what was needed (as a fully newcomer into rust).

Short Update: I could run the optimization for scalar function, it seems to work. I am not sure how to get the resulting get_best_param or get_param in the end, it seems that this function changed in 0.8.

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.03 ⚠️

Comparison is base (0bcc00c) 93.38% compared to head (003c181) 93.35%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #346      +/-   ##
==========================================
- Coverage   93.38%   93.35%   -0.03%     
==========================================
  Files         119      117       -2     
  Lines       18979    18803     -176     
==========================================
- Hits        17724    17554     -170     
+ Misses       1255     1249       -6     
Impacted Files Coverage Δ
argmin-math/src/ndarray_m/inv.rs 100.00% <100.00%> (ø)

... and 50 files with indirect coverage changes

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

@stefan-k
Copy link
Member

stefan-k commented May 4, 2023

I tried to implement the f64/f32 standard inverse for the ArgminInv (modification in the implementation of inv for ndarray). I also added a test for it.

Thanks a lot!! :)

For unknown compilation reasons on my machine (admittedly weird linux conf), I could not run the test nor use the library locally to check if that works. I will have to look later into it.

Have you seen this section of the book? The CI passes, so it should be fine.

Short Update: I could run the optimization for scalar function, it seems to work. I am not sure how to get the resulting get_best_param or get_param in the end, it seems that this function changed in 0.8.

You should be able to get an Option<&f64> via result.state().get_best_param(). Alternatively you should be able to access the best_param field of the state with result.state().best_param. (Yes, this should have better ergonomics ;))

@sdrap
Copy link
Contributor Author

sdrap commented May 4, 2023

Thanks, I could get it after a couple of try -> *res.state().best_param.as_ref().unwrap().

BTW: I was wondering how to get a termination done with newton when for instance $f^\prime'/f^{\prime\prime}' is below a certain tolerance level.

I am also thinking about getting a 1d version where the optimum should remain within an interval (for instance when the function is undefined (+infty) out of the bounds. But for that maybe I just implement a special solver since it is arguably quite special.

Many thanks in any cases, the library works like a charm.

@stefan-k
Copy link
Member

stefan-k commented May 5, 2023

I was wondering how to get a termination done with newton when for instance $f^\prime'/f^{\prime\prime}' is below a certain tolerance level.

Unfortunately argmin doesn't yet allow users to create their own stopping criteria (#91). You could however add this stopping criterion to the solver and issue a PR, similarly to how it is done here.

I am also thinking about getting a 1d version where the optimum should remain within an interval (for instance when the function is undefined (+infty) out of the bounds. But for that maybe I just implement a special solver since it is arguably quite special.

argmin unfortunately doesn't have a proper concept of bounds yet (apart from Simulated Annealing and Particle Swarm Optimization, where it is quite straight-forward). You can implement this in your own code by implementing the Solver trait. That way you are able to run the solver in the Executor with all its benefits. Feel free to get in touch if you run into problems with this, I'm happy to get some feedback about the ergonomics of implementing a solver.

Many thanks in any cases, the library works like a charm.

Thanks! :)

Copy link
Member

@stefan-k stefan-k left a comment

Choose a reason for hiding this comment

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

Thanks a lot! :)

@stefan-k stefan-k merged commit ae98919 into argmin-rs:main May 5, 2023
13 checks passed
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.

None yet

3 participants