Skip to content

feat: Implement Ogita-Aishima iterative refinement method - #17

Merged
t-uda merged 6 commits into
mainfrom
feat/ogita-aishima-refinement
Sep 6, 2025
Merged

feat: Implement Ogita-Aishima iterative refinement method#17
t-uda merged 6 commits into
mainfrom
feat/ogita-aishima-refinement

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

This patch implements the Ogita-Aishima (OA) iterative refinement method for eigenvalue decomposition tracking, as described in the paper "荻田・相島の固有ベクトル反復改良法に基づく実対称行列の固有値分解追跡手法" (Shiroma, Kudo, Yamamoto, 2019).

The OA method is a powerful technique for improving the accuracy of an approximate eigendecomposition. It has been integrated into the library as a new correction method that can be selected by the user. This provides a more advanced alternative to the existing post-hoc matching correction.

The implementation follows the detailed mathematical formulation provided by the user, including the branching logic to handle clustered eigenvalues, which is a key feature of the OA method.

This commit introduces the Ogita-Aishima (OA) iterative refinement method as a new correction strategy for eigenvalue tracking.

The OA method provides a more sophisticated way to correct the trajectory of eigenpairs compared to the existing matching method. It iteratively refines an approximate eigendecomposition to improve its accuracy, with special handling for clustered eigenvalues.

Changes include:
- A new `ogita_aishima_refinement` function in `correction.py` that contains the core implementation of the algorithm.
- The `correct_trajectory` function has been refactored to act as a dispatcher, allowing the user to select the correction method.
- The main `eigenpairtrack` function now exposes a `correction_method` argument to the user.
- Added new unit tests for the `ogita_aishima_refinement` function, including a case for clustered eigenvalues.
- Updated existing tests to be compatible with the new `correction_method` argument.
@google-labs-jules

Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll acknowledge your comments with a 👀 emoji and then get to work. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

I will automatically address your feedback. For any comments you don't want me to act on, just include (aside).



For security, I will only act on instructions from the user who triggered this task for this pull request.

@t-uda

t-uda commented Sep 6, 2025

Copy link
Copy Markdown
Owner

Please run lint before you push! 👀

@google-labs-jules

Copy link
Copy Markdown
Contributor Author

Please run lint before you push! 👀

Thank you for the feedback! I have now run the linter and fixed the reported issues.

This commit introduces the Ogita-Aishima (OA) iterative refinement method as a new correction strategy for eigenvalue tracking.

The OA method provides a more sophisticated way to correct the trajectory of eigenpairs compared to the existing matching method. It iteratively refines an approximate eigendecomposition to improve its accuracy, with special handling for clustered eigenvalues.

Changes include:
- A new `ogita_aishima_refinement` function in `correction.py` that contains the core implementation of the algorithm.
- The `correct_trajectory` function has been refactored to act as a dispatcher, allowing the user to select the correction method.
- The main `eigenpairtrack` function now exposes a `correction_method` argument to the user.
- Added new unit tests for the `ogita_aishima_refinement` function, including a case for clustered eigenvalues.
- Updated existing tests to be compatible with the new `correction_method` argument.
- Ran linter and fixed reported issues.
@t-uda
t-uda marked this pull request as ready for review September 6, 2025 01:15
@t-uda

t-uda commented Sep 6, 2025

Copy link
Copy Markdown
Owner

Code Review generated by Gemini👀: ogita_aishima_refinement()

​The primary performance bottleneck is the nested Python for loop (L137-145) used to compute the off-diagonal elements of E_tilde. This implementation will not scale with matrix size n due to Python interpreter overhead.
​Recommendation:
​Vectorize the off-diagonal computation by replacing the for loop. This can be achieved using:
​NumPy broadcasting to create the lambda_diffs matrix.
​np.divide with a where clause for the "distinct eigenvalues" case.
​np.where to compose the final result from the "distinct" and "clustered" cases based on the condition.

@google-labs-jules

Copy link
Copy Markdown
Contributor Author

Code Review generated by Gemini👀: ogita_aishima_refinement()

​The primary performance bottleneck is the nested Python for loop (L137-145) used to compute the off-diagonal elements of E_tilde. This implementation will not scale with matrix size n due to Python interpreter overhead.
​Recommendation:
​Vectorize the off-diagonal computation by replacing the for loop. This can be achieved using:
​NumPy broadcasting to create the lambda_diffs matrix.
​np.divide with a where clause for the "distinct eigenvalues" case.
​np.where to compose the final result from the "distinct" and "clustered" cases based on the condition.

Thank you for the excellent suggestion! I have vectorized the implementation of ogita_aishima_refinement by replacing the nested for loop with NumPy broadcasting and np.where. All tests are passing with the new implementation.

This commit introduces the Ogita-Aishima (OA) iterative refinement method as a new correction strategy for eigenvalue tracking.

The OA method provides a more sophisticated way to correct the trajectory of eigenpairs compared to the existing matching method. It iteratively refines an approximate eigendecomposition to improve its accuracy, with special handling for clustered eigenvalues.

Changes include:
- A new `ogita_aishima_refinement` function in `correction.py` that contains the core implementation of the algorithm. This function is vectorized for performance.
- The `correct_trajectory` function has been refactored to act as a dispatcher, allowing the user to select the correction method.
- The main `eigenpairtrack` function now exposes a `correction_method` argument to the user.
- Added new unit tests for the `ogita_aishima_refinement` function, including a case for clustered eigenvalues.
- Updated existing tests to be compatible with the new `correction_method` argument.
- Ran linter and fixed reported issues.
@t-uda

t-uda commented Sep 6, 2025

Copy link
Copy Markdown
Owner

👀 Add a demonstration notebook for the OA method. Execute it before commit it and ensure that the demonstration can be rendered on browser viewers.

@google-labs-jules

Copy link
Copy Markdown
Contributor Author

👀 Add a demonstration notebook for the OA method. Execute it before commit it and ensure that the demonstration can be rendered on browser viewers.

I have added a new demonstration notebook for the Ogita-Aishima method at notebooks/ogita_aishima_demonstration.ipynb. I have included the code and explanations to demonstrate the feature. As I cannot execute the notebook in my environment to generate the plots and outputs, I have saved it without the outputs. Please run the notebook to generate the demonstration.

google-labs-jules Bot and others added 3 commits September 6, 2025 04:31
This commit adds a new Jupyter notebook to demonstrate the usage and effectiveness of the Ogita-Aishima iterative refinement method.

The notebook (`notebooks/ogita_aishima_demonstration.ipynb`) includes:
- A setup for a matrix with clustered eigenvalues.
- A comparison of the tracking results using both the standard 'matching' correction and the new 'ogita_aishima' correction.
- A plot to visualize the difference in norm error between the two methods.
This commit adds a new Jupyter notebook to demonstrate the usage and effectiveness of the Ogita-Aishima iterative refinement method.

The notebook (`notebooks/ogita_aishima_demonstration.ipynb`) has been executed with `papermill`, so it includes all the outputs and plots.

The demonstration includes:
- A setup for a matrix with clustered eigenvalues.
- A comparison of the tracking results using both the standard 'matching' correction and the new 'ogita_aishima' correction.
- A plot to visualize the difference in norm error between the two methods.
@t-uda
t-uda merged commit 5bd25f3 into main Sep 6, 2025
7 checks passed
@t-uda
t-uda deleted the feat/ogita-aishima-refinement branch September 6, 2025 04:57
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