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

Fix the correlation matrix computation in Stouffers and Reports #901

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 7 deletions nimare/meta/ibma.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,10 @@ def _preprocess_input(self, dataset):
rowvar=True,
)
else:
self.inputs_["corr_matrix"] = np.zeros((n_studies, n_studies), dtype=float)
for bag in self.inputs_["data_bags"]["z_maps"]:
study_bag = bag["study_mask"]
self.inputs_["corr_matrix"][np.ix_(study_bag, study_bag)] = np.corrcoef(
bag["values"],
rowvar=True,
)
self.inputs_["corr_matrix"] = np.corrcoef(
self.inputs_["z_maps"],
rowvar=True,
)

def _generate_description(self):
description = (
Expand Down
12 changes: 4 additions & 8 deletions nimare/reports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,21 +528,17 @@ def __init__(

# Compute similarity matrix
if self.results.estimator.inputs_["corr_matrix"] is None:
n_studies = len(ids_)
if self.results.estimator.aggressive_mask:
voxel_mask = self.results.estimator.inputs_["aggressive_mask"]
corr = np.corrcoef(
self.results.estimator.inputs_[key_maps][:, voxel_mask],
rowvar=True,
)
else:
corr = np.zeros((n_studies, n_studies), dtype=float)
for bag in self.results.estimator.inputs_["data_bags"][key_maps]:
study_bag = bag["study_mask"]
corr[np.ix_(study_bag, study_bag)] = np.corrcoef(
bag["values"],
rowvar=True,
)
corr = np.corrcoef(
self.results.estimator.inputs_[key_maps],
rowvar=True,
)
else:
corr = self.inputs_["corr_matrix"]

Expand Down
9 changes: 0 additions & 9 deletions nimare/tests/test_meta_kernel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Test nimare.meta.kernel (CBMA kernel estimators)."""

import time

import nibabel as nib
import numpy as np
import pytest
Expand Down Expand Up @@ -177,24 +175,17 @@ def test_ALEKernel_memory(testdata_cbma, tmp_path_factory):
ma_maps_cached = kern_cached.transform(coord, masker=testdata_cbma.masker, return_type="array")

kern = kernel.ALEKernel(sample_size=20, memory=None)
start = time.time()
ma_maps = kern.transform(coord, masker=testdata_cbma.masker, return_type="array")
done = time.time()
elapsed = done - start

assert np.array_equal(ma_maps_cached, ma_maps)

# Test that memory is actually used
kern_cached_fast = kernel.ALEKernel(sample_size=20, memory=str(cachedir), memory_level=2)
start_chached = time.time()
ma_maps_cached_fast = kern_cached_fast.transform(
coord, masker=testdata_cbma.masker, return_type="array"
)
done_cached = time.time()
elapsed_cached = done_cached - start_chached

assert np.array_equal(ma_maps_cached_fast, ma_maps)
assert elapsed_cached < elapsed


def test_MKDA_kernel_sum_across(testdata_cbma):
Expand Down
Loading