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

[BUGFIX] Fixes CI + other tests #76

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/fugw/scripts/coarse_to_fine.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,13 @@ def compute_sparsity_mask(
device = torch.device("cuda", 0)
else:
device = torch.device("cpu")

# Convert coarse plan to numpy
coarse_plan = coarse_mapping.pi.to("cpu").numpy()
if method == "quantile":
# Method 1: keep first percentile
threshold = np.percentile(coarse_mapping.pi, 99.95)
rows, cols = np.nonzero(coarse_mapping.pi > threshold)
threshold = np.percentile(coarse_plan, 99.95)
rows, cols = np.nonzero(coarse_plan > threshold)

elif method == "topk":
# Method 2: keep topk indices per line and per column
Expand All @@ -328,12 +331,12 @@ def compute_sparsity_mask(
rows = np.concatenate(
[
np.arange(source_sample.shape[0]),
np.argmax(coarse_mapping.pi, axis=0),
np.argmax(coarse_plan, axis=0),
]
)
cols = np.concatenate(
[
np.argmax(coarse_mapping.pi, axis=1),
np.argmax(coarse_plan, axis=1),
np.arange(target_sample.shape[0]),
]
)
Expand Down
11 changes: 7 additions & 4 deletions tests/mappings/test_sparse_barycenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"device, callback",
product(devices, callbacks),
)
def test_fugw_barycenter(device, callback):
def test_fugw_sparse_barycenter(device, callback):
np.random.seed(0)
bthirion marked this conversation as resolved.
Show resolved Hide resolved
n_subjects = 4
n_voxels = 100
Expand All @@ -39,18 +39,21 @@ def test_fugw_barycenter(device, callback):
weights_list.append(weights)
features_list.append(features)

fugw_barycenter = FUGWSparseBarycenter()
geometry_embedding_normalized = (
geometry_embedding / geometry_embedding.norm()
)
fugw_sparse_barycenter = FUGWSparseBarycenter()

# Fit the barycenter
(
barycenter_weights,
barycenter_features,
plans,
losses_each_bar_step,
) = fugw_barycenter.fit(
) = fugw_sparse_barycenter.fit(
weights_list,
features_list,
geometry_embedding,
geometry_embedding_normalized,
mesh_sample=mesh_sample,
coarse_mapping_solver_params={"nits_bcd": 2, "nits_uot": 5},
fine_mapping_solver_params={"nits_bcd": 2, "nits_uot": 5},
Expand Down