Skip to content

Replace Least-Squares Procrustes Scalar Calculation with Spread-Matching Alternative - #79

Open
kbcoulter wants to merge 1 commit into
ohsu-comp-bio:developfrom
kbcoulter:spread_match_scale
Open

kbcoulter wants to merge 1 commit into
ohsu-comp-bio:developfrom
kbcoulter:spread_match_scale

Conversation

@kbcoulter

Copy link
Copy Markdown
Contributor

Summary:

In calculating the optimal scalar for procrustes, solving using Least Squares shrinks toward the centroid whenever anchor correspondence is noisy. For our purposes, this ruins scaling by shrinking the transformed (source) embeddings from the optimal size. Changes scale to match the target's spread directly without this bias, at the cost of no longer being RMSD-optimal.

Changes:

  • procrustes_scale_centered() now delegates to procrustes_scale() on pre-centered data

  • procrustes_scale() and procrustes_scale_centered() are scalar-only (not per-dim vector) going forward.

  • Updated two procrustes_scale() tests and one procrustes_scale_centered() test. They now assert k's shape explicitly.

Notes:

This PR removes all scaling functions using the traditional, RMSD optimizing, LeastSquares approach. If it is desirable to keep this in the kit, for other alignment cases (perhaps optimizing reconstruction), I am happy to bring that functionality back.

- src/embkit/align.py: Scale factor no longer least-squares
	- procrustes_scale() and procrustes_scale_centered() now calculated w/o least-squares (p correlation), now avoids shrinking toward the centroid under noisy anchor correspondence
	- procrustes_scale_centered() now delegates to procrustes_scale()
	- procrustes_scale() removed vector scaling, not optimized as intended

- tests/preprocessing/test_align.py: Fix tests that were passing by coincidence after changes
	- testing for procrustes_scale() and procrustes_scale_centered(): now assert k is scalar, so regression back to vector/per-dim behavior is caught.
@kellrott
kellrott requested a balanced review from Copilot October 5, 2026 17:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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