Skip to content

Transform API#78

Merged
denehoffman merged 17 commits intorefactor-unified-apifrom
transform-api
Sep 20, 2025
Merged

Transform API#78
denehoffman merged 17 commits intorefactor-unified-apifrom
transform-api

Conversation

@denehoffman
Copy link
Copy Markdown
Owner

@denehoffman denehoffman commented Sep 20, 2025

This creates a new set of traits to handle transforms and bounds. Not only does it introduce some bounds which are faster to compute, it gives the user a clean interface for choosing and creating their own bounds transformations. The general transforms are also useful in many ways, and we provide an example which shows their versatility. Finally, this removes generic inputs from standard CostFunction and Gradient traits and adds new Generic versions of those traits for algorithms which can handle them. This solidifies the choice of nalgebra as a backend for most standard algorithms. We may in the future make these algorithms more generic via a breaking change if performance is poor on large input spaces (for instance, using faer instead to handle large matrix operations).

This generally differentiates algorithms which can natively handle bounds and those which cannot. Additionally, it gives the Nelder-Mead algorithm a native way to handle bounds.

denehoffman and others added 17 commits September 11, 2025 23:13
…hms from bounds transforms

This is a potential feature which would simplify and clarify the difference between an algorithm which supports bounds "out of the box" like L-BFGS-B or (as I recently discovered) Nelder-Mead from those which support it via a MINUIIT-style change of coordinates. These changes of coordinates are now a separate trait, and `Bounds` implements this trait. Algorithms which don't natively support bounds can add a bounds transform with a different method from the `with_bounds` method: `with_transform`.

Transformations are also nice because they can transform an entire problem space. For example, when fitting a multivariate normal distribution, symmetric positive-semidefinite covariance matrices are not only desirable, but required. However, with box bounds alone, there is no way to ensure this quality. A coordinate transform (`SymmetricPositiveSemidefiniteTransform`) ensures this property, allowing internal parameters to take any value given by the algorithm in the same way that bounds transforms allow algorithms to work on an unbounded space.
…tency in MaxSteps, and add message to MaxSteps
… L-BFGS-B. However, this will need a refactor, I'm running into some issues with how this currently is set up, but I wanted to commit this just to make sure I have it
…Input on standard cost function, finish and test transforms, and add demo spherical coordinate transform
…tional to_internal_jacobian/hessian methods, remove SPD transform, and some perf lints
Big change to make it easier for users to not only implement their own bounds methods, but also to use legacy methods like Minuit/LMFIT bounds. Also a bunch of clippy lints and docstrings.
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 20, 2025

Codecov Report

❌ Patch coverage is 85.93571% with 245 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.99%. Comparing base (64e511b) to head (c695705).
⚠️ Report is 64 commits behind head on refactor-unified-api.

Files with missing lines Patch % Lines
src/traits/transform.rs 70.14% 60 Missing ⚠️
src/algorithms/gradient_free/nelder_mead.rs 72.77% 55 Missing ⚠️
src/core/transforms.rs 94.15% 37 Missing ⚠️
src/core/summary.rs 14.28% 24 Missing ⚠️
src/traits/boundlike.rs 80.51% 15 Missing ⚠️
src/algorithms/particles/swarm.rs 67.74% 10 Missing ⚠️
src/algorithms/mcmc/aies.rs 68.00% 8 Missing ⚠️
src/test_functions/rosenbrock.rs 50.00% 7 Missing ⚠️
src/algorithms/gradient/lbfgsb.rs 82.14% 5 Missing ⚠️
src/algorithms/particles/pso.rs 54.54% 5 Missing ⚠️
... and 7 more
Additional details and impacted files
@@                    Coverage Diff                    @@
##           refactor-unified-api      #78       +/-   ##
=========================================================
+ Coverage                 55.15%   86.99%   +31.83%     
=========================================================
  Files                        27       32        +5     
  Lines                      3771     5936     +2165     
=========================================================
+ Hits                       2080     5164     +3084     
+ Misses                     1691      772      -919     

☔ 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.

@denehoffman denehoffman merged commit bc00171 into refactor-unified-api Sep 20, 2025
7 of 9 checks passed
@denehoffman denehoffman deleted the transform-api branch September 20, 2025 20:34
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Sep 20, 2025

CodSpeed Performance Report

Merging #78 will improve performances by 31.69%

Comparing transform-api (c695705) with refactor-unified-api (7272e54)1

Summary

⚡ 13 improvements
✅ 5 untouched

Benchmarks breakdown

Benchmark BASE HEAD Change
gradient[256] 751.9 µs 571.7 µs +31.54%
gradient[64] 54.3 µs 43.6 µs +24.75%
hessian[16] 143.5 µs 124.3 µs +15.45%
hessian[256] 383.7 ms 291.4 ms +31.69%
hessian[64] 6.5 ms 5.1 ms +27.32%
Rosenbrock (adaptive)[2] 114 µs 100.9 µs +12.91%
Rosenbrock (adaptive)[3] 260.9 µs 231.4 µs +12.75%
Rosenbrock (adaptive)[4] 174.2 µs 156.5 µs +11.32%
Rosenbrock (adaptive)[5] 727.6 µs 648.3 µs +12.24%
Rosenbrock[2] 114.6 µs 101.5 µs +12.94%
Rosenbrock[3] 218.8 µs 194.5 µs +12.46%
Rosenbrock[4] 143.1 µs 128.9 µs +11.03%
Rosenbrock[5] 174 µs 157.5 µs +10.45%

Footnotes

  1. No successful run was found on refactor-unified-api (552733b) during the generation of this report, so 7272e54 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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.

1 participant