Skip to content

Add new matrix reconditioning approach. - #200

Merged
arm61 merged 5 commits into
mainfrom
reconditioning
Dec 19, 2025
Merged

Add new matrix reconditioning approach.#200
arm61 merged 5 commits into
mainfrom
reconditioning

Conversation

@arm61

@arm61 arm61 commented Dec 16, 2025

Copy link
Copy Markdown
Collaborator

This is very much an experimental approach that I am hoping to have a student investigate in detail over summer. Hence this does not affect the standard operation of kinisi.

Just need to write test for this.

@github-actions

github-actions Bot commented Dec 16, 2025

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1984 1887 95% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
kinisi/diffusion.py 90% 🟢
kinisi/diffusion_analyzer.py 81% 🟢
kinisi/tests/test_diffusion.py 100% 🟢
TOTAL 90% 🟢

updated for commit: 419c3dd by action🐍

@arm61
arm61 requested review from Harry-Rich and jd15489 December 16, 2025 16:39
@arm61

arm61 commented Dec 16, 2025

Copy link
Copy Markdown
Collaborator Author

Also removing some code that added very little but raised a lot of warnings each run.

@Harry-Rich Harry-Rich left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can't really comment on method, happy to approve, see what you think about comments

def test_eigenvalue_clipping(self):
matrix = np.random.random((100, 100)) + 100
reconditioned_matrix = eigenvalue_clipping(matrix)
assert not np.allclose(matrix, reconditioned_matrix)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This only really tests the dimensionality right, should we test that is it returning the correct values?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think once we have investigated the different clipping approaches a real test is a good idea. This is just checking that something has changed.

Comment thread kinisi/diffusion.py
Comment thread kinisi/diffusion.py
:param a: input array
:return: element wise maximum of (a, 0)
"""
return np.maximum(a, np.zeros_like(a))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

np.maximum(a, 0.0)

np maximum maintains the array size.

Comment thread kinisi/diffusion.py
new_eigenvalues = np.copy(eigenvalues)
new_eigenvalues[new_eigenvalues < lambda_plus] = lambda_minus

new_corr = (eigenthings.eigenvectors @ np.diag(new_eigenvalues) @ np.linalg.inv(eigenthings.eigenvectors)).real

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe define eigenvectors similarly to eigenvalues for consistency?

Comment thread kinisi/diffusion.py
values=cov_nearest(
minimum_eigenvalue_method(cov[self.diff_regime :, self.diff_regime :], self._cond_max)
),
unit=self.dg['da'].unit ** 2,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Don't find dg or da naming very intuitive, but this is not really a new change, perhaps something to think about (I am sure there was some rationale)

@arm61
arm61 merged commit 5b30669 into main Dec 19, 2025
8 checks passed
@arm61
arm61 deleted the reconditioning branch December 19, 2025 14:24
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.

2 participants