Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condense distance matrix that was not. Pep8 + test pass #1084

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

VincentBeaud
Copy link
Contributor

@VincentBeaud VincentBeaud commented Dec 12, 2024

Quick description

Closes #1060

Type of change

Check the relevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Provide data, screenshots, command line to test (if relevant)

...

Checklist

  • My code follows the style guidelines of this project (run autopep8)
  • I added relevant citations to scripts, modules and functions docstrings and descriptions
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I moved all functions from the script file (except the argparser and main) to scilpy modules
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@VincentBeaud
Copy link
Contributor Author

Passes test, but no validation that it doesn't change the result. It shouldn't.. but maybe have @frheault validate the fix since I think he's more familiar with spatial manipulations
@arnaudbore

@EmmaRenauld EmmaRenauld requested a review from frheault December 12, 2024 15:54
@@ -36,9 +37,11 @@ def compute_olo(array):
if array.ndim != 2:
raise ValueError('RCM can only be applied to 2D array.')

Z = hierarchy.ward(array)
condensed_array = squareform(array)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why squareform would help here? A connectivity array (like streamline count) is already a form of distance matrix. I think it is fine as it was, no?

What was your goal when you found and added squareform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When trying to solve this issue, I learned that a distance matrix is symmetric and can be condensed into a a list or vector. Similarly to a graph adjacency matrix that you transform into an adjacency list.

The error was that the matrix looked "suspiciously like an uncondensed distance matrix" when used in the optimal_leaf_ordering function. Using a symmetric (redundant) distance matrix in scipy functions gives a warning because it's suboptimal. (I suppose)

Squareform converts a uncondensed distance matrix into a condensed one and vice versa. The error disapeared after that.

Copy link
Member

Choose a reason for hiding this comment

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

Ok but our matrices is real data, we can't change it to fix an error. Did you verify if the input/output still made sense?

Otherwise I would leave it like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean by real data. Maybe we should walk about it in person. 😄

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.46%. Comparing base (5bcfd7f) to head (c4cebf7).
Report is 18 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1084      +/-   ##
==========================================
+ Coverage   69.45%   69.46%   +0.01%     
==========================================
  Files         447      447              
  Lines       24025    24054      +29     
  Branches     3280     3291      +11     
==========================================
+ Hits        16687    16710      +23     
- Misses       5943     5946       +3     
- Partials     1395     1398       +3     
Components Coverage Δ
Scripts 70.26% <82.45%> (+<0.01%) ⬆️
Library 68.40% <100.00%> (+0.02%) ⬆️

@VincentBeaud
Copy link
Contributor Author

VincentBeaud commented Dec 19, 2024

Okay after discussion, squareform seems to result in the wrong permutations because there is data on the diagonal of the matrix that gets lost when condensed. Works with test data, but not with real data. We instead will simply mute the warning, as it's not a big deal.

The warning was already set to be muted in matrix_tools.py, but somehow it didn't work with the tests. So I added another line in the problematic test case to mute it again. Now we don't see it.

@VincentBeaud
Copy link
Contributor Author

Adding the simplefilter at the top of the test script does not seem to work. This is why I put it inside the test case.

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.

Todo: Fix scipy warning
2 participants