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

Update projector structure. And add ICA explained variance #685

Merged
merged 9 commits into from
Sep 5, 2024

Conversation

rcassani
Copy link
Member

@rcassani rcassani commented Feb 19, 2024

This PR adds code to compute the variance explained by the IC when using ICA decomposition.

The reasonable place to store these values is the SingVal field in the projector structure. However, this changes for back compatibility are needed as this field is currently either the PCA explained variance, or a string to identify other projectors ICA or REF (montage).

% There are 5 categories of projectors:
% - SSP_pca: CompMask=[Ncomp x 1], SingVal=[Ncomp x 1], Components=[Nchan x Ncomp]=U
% - SSP_mean: CompMask=1, SingVal=[], Components=[Nchan x 1]=U
% - ICA: CompMask=[Ncomp x 1], SingVal='ICA', Components=[Nchan x Ncomp]=W'
% - REF: CompMask=[], SingVal='REF', Components=[Nchan x Ncomp]=Wmontage
% - Other: CompMask=[], SingVal=[], Components=[Nchan x Nchan]=Projector=I-UUt

Tentative solution:
1. Use the Comment to identify the type of projector
2. Always require the projector Comment to have the type of projector on it

Implemented solution:

  • Add field 'Method' to 'Projector' structure to identify Projector
  • Support projectors without 'Method'. Get projector method from its content
  • Store ICA explained variance in SingVal

References:
mne-tools/mne-python#11141


Being F the original data, the independent components Y can be obtained by multiplying the unmixing matrix W with F. Then we can mix those ICs Y with the mixing matrix M (which is the inverse of W) to recover the observed data F this is to say F'

Y = W * F
F' = M * Y

Then we can compute the variance explained by each IC as:

varIcs = sum(M.^2, 1) .* transpose(sum(Y.^2, 2))
varIcs = varIcs / sum(varIcs)

However this is the explained variance of F', so these explained variances need to be scaled with ratio of variance between F' and F.

Fdiff = (F - M * Y)
rVarExp = 1 - (sum(sum(Fdiff.^2, 2)) ./ sum(sum(F.^2, 2)))

Variance in original data by each component
varIcs = rVarExp * varIcs

@rcassani rcassani changed the title ICA explained variance in original data Update projector structure. And add ICA explained variance Aug 27, 2024
@rcassani rcassani marked this pull request as ready for review August 27, 2024 15:20
toolbox/io/out_fopen_bst.m Outdated Show resolved Hide resolved
@rcassani rcassani merged commit 433faab into brainstorm-tools:master Sep 5, 2024
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.

1 participant