Update projector structure. And add ICA explained variance #685
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theprojector
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 projectorsICA
orREF
(montage).brainstorm3/toolbox/process/functions/process_ssp2.m
Lines 947 to 952 in e532c6d
Tentative solution:1. Use the Comment to identify the type of projector2. Always require the projector Comment to have the type of projector on itImplemented solution:
SingVal
References:
mne-tools/mne-python#11141
Being
F
the original data, the independent componentsY
can be obtained by multiplying the unmixing matrixW
withF
. Then we can mix those ICsY
with the mixing matrixM
(which is the inverse ofW
) to recover the observed dataF
this is to sayF'
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 betweenF'
andF
.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