-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: master
Are you sure you want to change the base?
Conversation
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? |
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. |
There was a problem hiding this 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.
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: |
There was a problem hiding this comment.
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.
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] |
There was a problem hiding this comment.
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.
pair_indices = np.array(pair_indices)[:, np.newaxis] |
Copilot uses AI. Check for mistakes.
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