Skip to content

add pairwise granger for subset of channel pairs #58

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

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

Conversation

leoscholl
Copy link

with large channel counts it can be useful to compute cross-spectral estimates and connectivity measures for just a subset of channels. i'm not sure if the way i accomplished this is the best approach or if you have other suggestions. it works for my purposes, anyway. let me know if you think it's useful

@edeno
Copy link
Contributor

edeno commented Mar 21, 2025

Hi @leoscholl,

Thank you for your contribution! For subsets of channels, could you not just put use that subset of signals or is there some efficiency that I'm not thinking of?

@leoscholl
Copy link
Author

I'm computing granger prediction from one channel to all other channels, so estimating the full pairwise matrix takes a long time (and a lot of memory, but i'm ignoring that problem for now) and most of the values aren't used.

@edeno edeno requested a review from Copilot April 2, 2025 20:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to compute connectivity measures and predictive power for a subset of channel pairs, addressing performance concerns when dealing with large channel counts.

  • Introduces a _subset_cross_spectral_matrix method to compute connectivity measures for specified channel pairs.
  • Adds a subset_pairwise_spectral_granger_prediction method to evaluate predictive power for given pair combinations.

Comment on lines +297 to +306
for x in _syu:
diag_out = self._expectation(
_complex_inner_product(
fourier_coefficients[..., [x], :],
fourier_coefficients[..., [x], :],
dtype=self._dtype,
)
)
csm[..., [x], [x]] = diag_out[..., 0]
for x in _sxu:
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

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

The diagonal computation is being performed separately for _syu and _sxu, which may lead to redundant processing if these arrays overlap. Consider computing the unique set of indices from both arrays and iterating over that set to avoid duplicate work.

Suggested change
for x in _syu:
diag_out = self._expectation(
_complex_inner_product(
fourier_coefficients[..., [x], :],
fourier_coefficients[..., [x], :],
dtype=self._dtype,
)
)
csm[..., [x], [x]] = diag_out[..., 0]
for x in _sxu:
unique_indices = xp.unique(xp.concatenate((_syu, _sxu)))
for x in unique_indices:

Copilot uses AI. Check for mistakes.

predictive_power = np.empty(new_shape)

for pair_indices in pairs:
pair_indices = np.array(pair_indices)[:, np.newaxis]
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

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

[nitpick] Converting pair_indices to a numpy array inside the loop introduces unnecessary overhead if pairs were already converted earlier. Consider pre-processing the pairs outside the loop to optimize performance.

Suggested change
pair_indices = np.array(pair_indices)[:, np.newaxis]

Copilot uses AI. Check for mistakes.

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