Skip to content

Fix generalized procrustes algorithm#217

Merged
FanwangM merged 1 commit intotheochem:mainfrom
msegado:patch-1
Feb 24, 2025
Merged

Fix generalized procrustes algorithm#217
FanwangM merged 1 commit intotheochem:mainfrom
msegado:patch-1

Conversation

@msegado
Copy link
Copy Markdown
Contributor

@msegado msegado commented Feb 21, 2025

The generalized procrustes implementation was never updating the reference shape -- in effect, this means it would always run just one iteration of the algorithm and then return because the change in ref would be zero. This PR adds the missing line to update the reference shape.

(Might also be a good idea to add a test which catches this in the future since the existing ones didn't -- though that could always be added later.)

The generalized procrustes implementation was never updating the reference shape -- in effect, this means it would always run just one iteration of the algorithm and then return because the change in ref would be zero. This PR adds the missing line to update the reference shape.

(Might also be a good idea to add a test which catches this in the future since the existing ones didn't -- though that could always be added later.)
@msegado
Copy link
Copy Markdown
Contributor Author

msegado commented Feb 21, 2025

Actually, I think there are a few other bugs I didn't address here:

  1. I believe new_distance_gpa is defined incorrectly... this should be a measure of the distance between the individual shapes and the mean, but currently measures the change in the mean from one iteration to the next. I think the correct version is something like the following, assuming what we want is the mean distance between individual shapes:
    new_distance_gpa = np.mean([np.square(arr - new_ref).sum() for arr in array_list], axis=0)
  2. I think a better convergence criterion to use is something like np.linalg.norm(ref - new_ref) < tol... i.e., we want to check if the reference shape is stable, rather than if the distance is stable.

@PaulWAyers PaulWAyers requested a review from FanwangM February 21, 2025 22:59
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@d4f2ab6). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #217   +/-   ##
=======================================
  Coverage        ?   94.13%           
=======================================
  Files           ?       11           
  Lines           ?      802           
  Branches        ?        0           
=======================================
  Hits            ?      755           
  Misses          ?       47           
  Partials        ?        0           
Files with missing lines Coverage Δ
procrustes/generalized.py 100.00% <100.00%> (ø)

@FanwangM
Copy link
Copy Markdown
Collaborator

Hi @msegado . Thank you for noticing the issue. I will take a closer look at the PR during the weekend.

@FanwangM
Copy link
Copy Markdown
Collaborator

Thanks for noticing the issue in the codes. I am going to merge this PR and add tests later. As for two questions you mentioned, I will open issues and address them. @msegado

@FanwangM FanwangM merged commit 04ba3fb into theochem:main Feb 24, 2025
@msegado
Copy link
Copy Markdown
Contributor Author

msegado commented Feb 25, 2025 via email

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