Skip to content

WIP: initialize continuous-time linear estimation in TF domain - #2641

Closed
jona-sassenhagen wants to merge 7 commits into
mne-tools:masterfrom
jona-sassenhagen:patch-17
Closed

jona-sassenhagen wants to merge 7 commits into
mne-tools:masterfrom
jona-sassenhagen:patch-17

Conversation

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

"rERPs for time-frequency data"

Currently fairly messy. Also, will probably murder your computer.

@choldgraf

@choldgraf

Copy link
Copy Markdown
Contributor

Haha, murder your computer is right :)

Just a thought - why doesn't this function allow you to provide epoch objects? Why only Raw objects? Esp doing the TFR stuff, that's going to result in a lot more RAM, no?

Also, if someone uses this for TFR regression, then how would they run statistics on this? In my experience I've only seen people do permutation cluster testing, but that's not possible with this right?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Just a thought - why doesn't this function allow you to provide epoch objects? Why only Raw objects?

The workflow for epochs objects is completely different under the hood. It would fit much better under Tal's function, linear_regression, than linear_regression_raw.

Esp doing the TFR stuff, that's going to result in a lot more RAM, no?

It's not even that bad, at least not for my usage cases. I guess with high sampling rate MEG and looking at gamma, it would be heavy.

Also, if someone uses this for TFR regression, then how would they run statistics on this? In my experience I've only seen people do permutation cluster testing, but that's not possible with this right?
Treat the single-subject regressions as a regular first-level analysis, and run second-level contrasts on the betas.

You have to understand betas as being fundamentally no different from means. They're a dependent variable; you can run cross-subject inference analyses on means or on regression coefficients, it's the same, you get a t value at the end.

Personally, I use cluster-based permutation tests on the time/channel or time/channel/frequency matrices.

@choldgraf

Copy link
Copy Markdown
Contributor

The workflow for epochs objects is completely different under the hood. It would fit much better under Tal's function, linear_regression, than linear_regression_raw.

Ah fair enough - I didn't dive into the code too closely, sorry if that was obvious.

It's not even that bad, at least not for my usage cases. I guess with high sampling rate MEG and looking at gamma, it would be heavy.

It isn't too bad in my case if you represent things with smaller numbers of bits (and obviously if you cut down on the number of frequency bands for the wavelets or decimate). Maybe we should cross that bridge if we get to it :)

Treat the single-subject regressions as a regular first-level analysis, and run second-level contrasts on the betas.
You have to understand betas as being fundamentally no different from means. They're a dependent variable; you can run cross-subject inference analyses on means or on regression coefficients, it's the same, you get a t value at the end.

Yeah, that's what I was thinking. I guess I was wondering if you could get any extra information about the variability of the betas that you wouldn't get by just doing a simple mean. e.g., if you bootstrapped your coefficients you could get an idea for their variability. I guess you could roll your own estimator to do this under the hood.

Personally, I use cluster-based permutation tests on the time/channel or time/channel/frequency matrices.

So do I - I guess it's just more common in ecog to keep analyses at the subject level, rather than doing a group-level analysis for TFR responses.

@choldgraf

Copy link
Copy Markdown
Contributor

Hehe, looks like I was already talking about this one last year too and forgot about it...got too many github issues on my mind :)

I think this is doing something similar to STRFs though not quite the same. A couple quick thoughts:

  • In my case, I only ever fit STRFs in a predictive model context. A really important part of STRF estimation is in doing cross-validation and getting prediction scores on held-out data. So that'd be some machinery to build in here.
  • A second thing would be adding some time-lag functionality. I don't think it'd be too tough to do this. Just say "give me the data, a sampling frequency, and a list of time lags to create in seconds", and return a matrix of (n_feats * n_lags x n_times).
  • I think epochs functionality would be helpful to include because you don't want datapoints from the same epoch falling into both the train / test sets. What I've been doing is attaching a label to each epoch and then using sklearn LabelShuffleSplit.
  • I think there's also a marketing thing a play here. My guess is people will search for "fit STRF model" or "fit encoding model" and I think some might miss these functions (like I did) which are embedded in stats. I don't really think of STRFs as a statistics function, in the same way that I don't think of an SVM as a statistics function. It's more of a predictive modeling thing to me, which has a different set of complications.

So to me it seems that doing something like STRF fitting would warrant a separate module or function. Maybe if we don't want to overlap too much with this more general OLS stuff, it could explicitly be a STRF model, rather than just an "encoding model"?

What do you guys think?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

In my case, I only ever fit STRFs in a predictive model context. A really important part of STRF estimation is in doing cross-validation and getting prediction scores on held-out data. So that'd be some machinery to build in here.

You can pass a custom solver.

This thing here only gives coefficients though, so if you want MSE etc., that'd optimally reference this.

A second thing would be adding some time-lag functionality. I don't think it'd be too tough to do this. Just say "give me the data, a sampling frequency, and a list of time lags to create in seconds", and return a matrix of (n_feats * n_lags x n_times).

That would mean refactoring out the code that's currently in lines 284-309.

Note, the XDawn module also duplicates exactly this functionality.

I think epochs functionality would be helpful to include because you don't want datapoints from the same epoch falling into both the train / test sets. What I've been doing is attaching a label to each epoch and then using sklearn LabelShuffleSplit.

That would fall under stats.linear_regression.

I think there's also a marketing thing a play here. My guess is people will search for "fit STRF model" or "fit encoding model" and I think some might miss these functions (like I did) which are embedded in stats. I don't really think of STRFs as a statistics function, in the same way that I don't think of an SVM as a statistics function. It's more of a predictive modeling thing to me, which has a different set of complications.
So to me it seems that doing something like STRF fitting would warrant a separate module or function. Maybe if we don't want to overlap too much with this more general OLS stuff, it could explicitly be a STRF model, rather than just an "encoding model"?

When I was discussing this module with Alex at the code sprint, he immediately recognized it was an encoding model (which had been so far unknown to me). I wouldn't mind a new encoding module eventually ... either including this function here, or just a lot of shared code.

I mean, this function basically does 3 things:

  • construct time-lagged predictor matrices
  • TF decompose raw data
  • solve linear system and return frequency x channel x time coefficients

And that'd be the backbone of a full STRF/encoding model, right?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

Is there recommended code for TF decomposition of raw data?

@Eric89GXL

@larsoner

larsoner commented Mar 2, 2016

Copy link
Copy Markdown
Member

I don't think we have anything mne-specific for time-freq decompositions of Raw

@choldgraf

Copy link
Copy Markdown
Contributor

I've just used cwt_morlet in the past...I think people have held off on building TFRs for Raw objects because they have a tendency to kersplode memory. That said, I still think it'd be great to have a method / class that handles full TFR decomposition without averaging in a clever memory-efficient way.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor Author

I'll put this one on ice until I've factored out building the pred matrix.

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.

3 participants