[Math] Add least squares method#1591
[Math] Add least squares method#1591DavidFang03 wants to merge 30 commits intoShamrock-code:mainfrom
Conversation
|
Thanks @DavidFang03 for opening this PR! You can do multiple things directly here: Once the workflow completes a message will appear displaying informations related to the run. Also the PR gets automatically reviewed by gemini, you can: |
Summary of ChangesHello @DavidFang03, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This PR introduces a significant amount of new numerical functionality, including a Levenberg-Marquardt solver, Cholesky decomposition, and an ODE integrator. The implementation is a good start, but there are several critical bugs and performance issues that need to be addressed. I've found incorrect assertions, indexing errors in matrix operations, and significant inefficiencies in the core optimization loop. The Python bindings also have performance problems due to unnecessary data copying. Additionally, some of the new tests contain bugs that could prevent them from correctly verifying the code's behavior, which aligns with the guideline to investigate the root cause in tests rather than allowing them to pass trivially. My review includes detailed suggestions to fix these issues and improve the overall quality and performance of the new code.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several new mathematical functionalities, including an Euler ODE solver, dynamic-sized matrix/vector classes (mat_d, vec_d), matrix transpose, Cholesky decomposition, Cholesky solver, and a Levenberg-Marquardt least squares method. The changes also include necessary pybind11 bindings to expose these functionalities to Python. Overall, the new features are valuable additions to the library. The provided feedback addresses various areas for improvement regarding const-correctness, potential runtime issues, code clarity, and adherence to best practices for numerical stability and portability.
|
|
||
| T u_prev = u0; | ||
| T u = u0; | ||
| for (T x = x0 + step; x < end; x += step) { |
There was a problem hiding this comment.
Using floating-point numbers directly in loop conditions like x < end can lead to precision issues, potentially causing the loop to terminate one step early or run one step too long due to accumulated floating-point errors. It's generally safer to iterate a fixed number of times or use a small epsilon for comparison, e.g., x < end - std::numeric_limits<T>::epsilon() * std::abs(end) * N where N is the number of steps.
| }; | ||
| u_prev = u0; | ||
| std::vector<T> X_backward, U_backward; | ||
| for (T x = x0 - step; x > start; x -= step) { |
Workflow reportworkflow report corresponding to commit d2cbdd1 Light CI is enabled. This will only run the basic tests and not the full tests. Pre-commit check reportPre-commit check: ✅ Test pipeline can run. Doxygen diff with
|
This PR implements
This will be useful for #1445 as I would like to numerically solve$\frac{du}{d \rho} = p(u, \rho)/\rho^2$ and fit with a non-linear function
I wasn't very familiar with
std::mdspanand The Levenberg-Marquardt has room for improvement but I believe it works well enough for #1145