You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DOC: order of operation in TFR functions needs to be clarified #7978
the tfr_morlet for time frequency decomposition has a parameter average which says:
If True average across Epochs.
The docs need to be updated to make it clear what the order of operations is. First averaging then decomposition? Or the other way around? What are the steps?
Yeah that test looks broken. We should move to assert_allclose and probably just use rtol there (unless we expect some near-zero values, in which case a suitable atol should be chosen based on what "zero-like" means for the data)
The critical part is where is the magnitude taken. decomp/mag/ave will be different from decomp/ave/mag (with the latter being equivalent to ave/decomp/mag).
this test makes no sense. You should not expect the TFR of the epochs to be the same as the evoked.
You should expect the TFR averaged across epochs to be the same as the TFR of the evoked if the magnitude is taken at the end (or not at all) for both. Maybe that's what the test was trying to check? And maybe it was wrong about when the average is taken (i.e., before or after the magnitude is taken)? Someone will need to dig into the code to check...
I agree with @agramfort and think the test was in error. the procedure to compute total power is to decomp/mag/ave. otherwise you are computing evoked total power which isn't (generally) what you want.
I should note that the surrounding assert_array_almost_equal are testing meaningful things and currently are trivially passing because of the lack of a decimal parameter
Sounds reasonable to me, @bloyl would you be up for fixing the code to use assert_allclose with rtol only and document the order of transformations in some TFR computing function (and maybe refer other ones to look at the Notes for that one)?
average : bool, default True
If False return an EpochsTFR containing separate tfrs for each epoch.
If True return an AverageTFR containing the average of all tfrs across epochs.
I think that's good but I would add some more detail:
average : bool, default True
If False return an EpochsTFR containing separate tfrs for each epoch.
If True return an AverageTFR containing the average of all tfrs across epochs.
AverageTFR is equivalent to EpochsTFR.average(), but setting average=True will
be more memory efficient than setting average=False and later calling
EpochsTFR.average().
Activity
bloyl commentedon Jul 8, 2020
I'm relatively confident that the order is
if you do the following
I'm pretty sure that
a == b.average()sappelhoff commentedon Jul 8, 2020
That makes me wonder why there is an
averageparameter at all --> mne.Epochs doesn't have one either? 🤔agramfort commentedon Jul 8, 2020
bloyl commentedon Jul 8, 2020
I think there might be a problem in the test
The following line in the test should fail
mne-python/mne/time_frequency/tests/test_tfr.py
Line 109 in 2965cc3
but it passes because
assert_array_almost_equalonly checks 6 decimal places and(Pdb) power.data.max() 2.1955190395488294e-21and in fact
assert_array_almost_equal(power.data, power_evoked.data, 22)fails with aMax relative difference: 681137.62395224larsoner commentedon Jul 8, 2020
Yeah that test looks broken. We should move to
assert_allcloseand probably just usertolthere (unless we expect some near-zero values, in which case a suitableatolshould be chosen based on what "zero-like" means for the data)agramfort commentedon Jul 8, 2020
larsoner commentedon Jul 8, 2020
The critical part is where is the magnitude taken. decomp/mag/ave will be different from decomp/ave/mag (with the latter being equivalent to ave/decomp/mag).
You should expect the TFR averaged across epochs to be the same as the TFR of the evoked if the magnitude is taken at the end (or not at all) for both. Maybe that's what the test was trying to check? And maybe it was wrong about when the average is taken (i.e., before or after the magnitude is taken)? Someone will need to dig into the code to check...
agramfort commentedon Jul 8, 2020
bloyl commentedon Jul 8, 2020
I agree with @agramfort and think the test was in error. the procedure to compute total power is to decomp/mag/ave. otherwise you are computing evoked total power which isn't (generally) what you want.
bloyl commentedon Jul 8, 2020
I should note that the surrounding
assert_array_almost_equalare testing meaningful things and currently are trivially passing because of the lack of adecimalparameterlarsoner commentedon Jul 8, 2020
Sounds reasonable to me, @bloyl would you be up for fixing the code to use
assert_allclosewithrtolonly and document the order of transformations in some TFR computing function (and maybe refer other ones to look at the Notes for that one)?bloyl commentedon Jul 8, 2020
Sure although Docs aren't exactly my strong suit.
@sappelhoff what do you think of
sappelhoff commentedon Jul 9, 2020
I think that's good but I would add some more detail: