treder / MVPA-Light

Matlab toolbox for classification and regression of multi-dimensional data
MIT License
70 stars 35 forks source link

Spatiotemporal searchlight #14

Closed schoffelen closed 4 years ago

schoffelen commented 4 years ago

OK, what about this one then? :) I have created a test/train pair of functions for the naive_bayes classifier that can handle the neighbours internally (assuming them to be all(0,1) (not tested)). The overhead is done in ft_statistics_mvpa, which will call mv_crossvalidate etc. The speed up is really considerable.

treder commented 4 years ago

Looking good. I've also been thinking about this topic and there may be a non-messy way for solving it within MVPA-Light (including saving the for loop): introduce a new parameter cfg.append_dimension = [ ] in mv_classify. If set, the respective dimension of the data gets appended as an extra dimension to the training data.

Example: X is [samples x channels x time points]. Normally mv_classify would loop over dimension 3 (time). Now you set cfg.append_dimension = 3 and the third dimension is appended to the training data i.e. the classifier will be provided with [train samples x channels x time points].

The code stays identical when cfg.append_dimension = [ ], we only add some alternative code if it isn't. In the latter case, we can append e.g. the neighbours to the hyperparameter struct. I think for now just a few classifiers might benefit from this and the user has to be aware of which classifiers do (but I can easily add a sanity check in mv_check_inputs that checks for this).

Would this work with the FieldTrip side? If so I can implement it by next week I think.

schoffelen commented 4 years ago

The added functions (i.e. the neighbours aware train/test functions) now seem to work just fine when they are accessed through mvcrossvalidate (which is how I have now implemented it in fieldtrip). I must say that I haven't checked whether it works in the other mv* functions, but I suspect not. :) So, right at the moment, things are still a bit hacky.

treder commented 4 years ago

Sooo ... I've created a new branch 'embed_dimensions' where we can safely play around with your idea. In this branch, mv_classify has been changed: If you set cfg.append = true then all the search dimensions get appended to the train/test data, so the data going into the classifier is [train samples x ... (search dimensions) ... x features] for an arbitrary number of search dimensions. Also cfg.neighbours gets added to the hyperparameter struct, see ll. 355+ in mv_classify. Will this do the job?

If so, can you please modify your naive_bayes and set up a pull request for the embed_dimensions branch? Btw: It looks to me like you have it hardcoded two searchlight dimensions in test_naive_bayes, can you make it work with arbitrary number of dimensions? Thanks.

schoffelen commented 4 years ago

Thanks Matthias, I have now (finally) created a new PR that builds on the embed_dimensions branch. I think it works fine on my end. I will close this one.