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

[FEAT] Add coarse-to-fine barycenter estimation #45

Merged
merged 53 commits into from
May 27, 2024

Conversation

pbarbarant
Copy link
Collaborator

@pbarbarant pbarbarant commented Apr 17, 2024

Implements coarse-to-fine estimation of barycenters with sparse transport plans. Closes #52

  • Docstrings
  • Unit tests

@pbarbarant pbarbarant added the enhancement New feature or request label Apr 17, 2024
@pbarbarant pbarbarant marked this pull request as draft April 17, 2024 14:21
Copy link
Collaborator

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

LGTM, but the test could be more informative.

fine_mapping_solver_params={"nits_bcd": 2, "nits_uot": 10},
device=device,
verbose=True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only a smoke test ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes this solely for the purpose of testing that everything runs regardless the validity of the transport plan.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need also a full test ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added new shape assertions + type checks

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good step forward.
But we may also want to test that the estimated barycenters are not crazy. Should we consider that in another PR for sparse and non-sparse baycenters altogether ?

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we could test edge cases (although this may require using external libraries):

  • one could test that alpha=0 returns wasserstein barycenters similar to that of POT
  • similarly, one could test that alpha=1 returns gromov barycenters similar to that of POT

@pbarbarant
Copy link
Collaborator Author

Fixing tests once #48 is merged.

@pbarbarant pbarbarant marked this pull request as ready for review May 2, 2024 15:11
@bthirion
Copy link
Collaborator

bthirion commented May 2, 2024

Cna you take care of the failing tests ? LGTM otherwise.

Copy link
Collaborator

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

LGTM otherwise.

fine_mapping_solver_params={"nits_bcd": 2, "nits_uot": 10},
device=device,
verbose=True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need also a full test ?

@pbarbarant
Copy link
Collaborator Author

New issue #52, sometimes features contain NaNs

Copy link
Collaborator

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

I like the homogeneous API !

The docstrings can still be improved a little bit...

fine_mapping_solver_params={"nits_bcd": 2, "nits_uot": 10},
device=device,
verbose=True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good step forward.
But we may also want to test that the estimated barycenters are not crazy. Should we consider that in another PR for sparse and non-sparse baycenters altogether ?

src/fugw/mappings/sparse_barycenter.py Outdated Show resolved Hide resolved
Co-authored-by: bthirion <bertrand.thirion@inria.fr>
@pbarbarant
Copy link
Collaborator Author

I agree that future issues should be resolved in a new PR. I'm currently confronting the new features to real data which will bring its own set of bugs, but let's keep that separate.

@bthirion
Copy link
Collaborator

Agreed. Can you look at the failing test ?

@pbarbarant
Copy link
Collaborator Author

Agreed. Can you look at the failing test ?

All fixed!

Copy link
Collaborator

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

LGTM, thx.

@bthirion
Copy link
Collaborator

@alexisthual do you want to take a look ? Best,

@pbarbarant pbarbarant merged commit ce9e5f1 into alexisthual:main May 27, 2024
7 checks passed
@pbarbarant pbarbarant deleted the feat_coarse_to_fine_bary branch May 27, 2024 14:00
Copy link
Owner

@alexisthual alexisthual left a comment

Choose a reason for hiding this comment

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

LGTM!

Here are a few general comments that I think could be addressed in different PRs:

  • it would be nice to add docstrings to mappings/{barycenter,sparse_barycenter}.py (they would appear in the documentation)
  • it might never be useful, but the static method update_barycenter_geometry() is currently missing from FUGWSparseBarycenter (I'm totally fine with that, as we probably don't need to learn a matrix of anatomical distances between vertices at the moment -- I think it could be useful if someone were to compute FUGW barycenters using connectomes for anatomical distances for instance)

Comment on lines +121 to +122
source_sample=mesh_sample,
target_sample=mesh_sample,
Copy link
Owner

Choose a reason for hiding this comment

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

I might be wrong, but I feel that you might need different values for mesh_sample across individuals if their data lie on different meshes. The barycenter might need its own mesh_sample as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are definitely right. However we agreed with @bthirion to keep the same geometry/mesh as for now. Moreover I'm afraid of the large memory/speed slowdown that we could get if we individualize the geometry of each individual. Maybe a NotImplementedError would be the best fit ? I'll open an issue...

Comment on lines +21 to +26
@pytest.fixture(scope="session", autouse=True)
def ignore_sparse_csr_warning():
"""Remove the warning for sparse CSR tensor support."""
warnings.filterwarnings(
"ignore", ".*Sparse CSR tensor support is in beta state.*"
)
Copy link
Owner

Choose a reason for hiding this comment

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

I had never used this, nice trick! :)

Comment on lines +356 to +358
mask: torch.Tensor or None
Sparsity mask to use when fitting the fine mapping.
If None, a mask will be computed from the coarse mapping.
Copy link
Owner

Choose a reason for hiding this comment

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

Feel free to ignore this comment, but would rather name this variable sparsity_mask so that it's not confused with a nilearn masker.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point

fine_mapping_solver_params={"nits_bcd": 2, "nits_uot": 10},
device=device,
verbose=True,
)
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we could test edge cases (although this may require using external libraries):

  • one could test that alpha=0 returns wasserstein barycenters similar to that of POT
  • similarly, one could test that alpha=1 returns gromov barycenters similar to that of POT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Dense/Sparse barycenters features contain NaNs
3 participants