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
MRG: deprecated ConcatenateChannels and renamed EpochVectorizer #2361
Changes from 8 commits
109f927
d068182
ea59c8e
5d61db2
3a5e227
30095f0
68de328
768d81e
7d18efd
d453f5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
band_stop_filter) | ||
from ..time_frequency import multitaper_psd | ||
from ..externals import six | ||
from ..utils import _check_type_picks | ||
from ..utils import _check_type_picks, deprecated | ||
|
||
|
||
class Scaler(TransformerMixin): | ||
|
@@ -147,13 +147,13 @@ def inverse_transform(self, epochs_data, y=None): | |
return X | ||
|
||
|
||
@deprecated("Class 'ConcatenateChannels' has been renamed to " | ||
"'EpochsVectorizer' and will be removed in release 0.11.") | ||
class ConcatenateChannels(TransformerMixin): | ||
"""Concatenates data from different channels into a single feature vector | ||
|
||
Parameters | ||
---------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it didn't pass doc tests because of the call to deprecated function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't fix it this way, fix it by adding the function or class name here: https://github.com/mne-tools/mne-python/blob/master/mne/tests/test_docstring_parameters.py#L64 |
||
info : instance of Info | ||
The measurement info. | ||
|
||
Attributes | ||
---------- | ||
|
@@ -247,6 +247,107 @@ def inverse_transform(self, X, y=None): | |
return X.reshape(self.n_epochs, self.n_channels, self.n_times) | ||
|
||
|
||
class EpochsVectorizer(TransformerMixin): | ||
"""EpochsVectorizer transforms epoch data to fit into a scikit-learn pipeline. | ||
|
||
Parameters | ||
---------- | ||
info : instance of Info | ||
The measurement info. | ||
|
||
Attributes | ||
---------- | ||
n_epochs : int | ||
The number of epochs. | ||
n_channels : int | ||
The number of channels. | ||
n_times : int | ||
The number of time points. | ||
|
||
""" | ||
def __init__(self, info=None): | ||
self.info = info | ||
self.n_epochs = None | ||
self.n_channels = None | ||
self.n_times = None | ||
|
||
def fit(self, epochs_data, y): | ||
"""For each epoch, concatenate data from different channels into a single | ||
feature vector. | ||
|
||
Parameters | ||
---------- | ||
epochs_data : array, shape (n_epochs, n_channels, n_times) | ||
The data to concatenate channels. | ||
y : array, shape (n_epochs,) | ||
The label for each epoch. | ||
|
||
Returns | ||
------- | ||
self : instance of ConcatenateChannels | ||
returns the modified instance | ||
""" | ||
if not isinstance(epochs_data, np.ndarray): | ||
raise ValueError("epochs_data should be of type ndarray (got %s)." | ||
% type(epochs_data)) | ||
|
||
return self | ||
|
||
def transform(self, epochs_data, y=None): | ||
"""For each epoch, concatenate data from different channels into a single | ||
feature vector. | ||
|
||
Parameters | ||
---------- | ||
epochs_data : array, shape (n_epochs, n_channels, n_times) | ||
The data. | ||
y : None | array, shape (n_epochs,) | ||
The label for each epoch. | ||
If None not used. Defaults to None. | ||
|
||
Returns | ||
------- | ||
X : array, shape (n_epochs, n_channels * n_times) | ||
The data concatenated over channels | ||
""" | ||
if not isinstance(epochs_data, np.ndarray): | ||
raise ValueError("epochs_data should be of type ndarray (got %s)." | ||
% type(epochs_data)) | ||
|
||
epochs_data = np.atleast_3d(epochs_data) | ||
|
||
n_epochs, n_channels, n_times = epochs_data.shape | ||
X = epochs_data.reshape(n_epochs, n_channels * n_times) | ||
# save attributes for inverse_transform | ||
self.n_epochs = n_epochs | ||
self.n_channels = n_channels | ||
self.n_times = n_times | ||
|
||
return X | ||
|
||
def inverse_transform(self, X, y=None): | ||
"""For each epoch, reshape a feature vector into the original data shape | ||
|
||
Parameters | ||
---------- | ||
X : array, shape (n_epochs, n_channels * n_times) | ||
The feature vector concatenated over channels | ||
y : None | array, shape (n_epochs,) | ||
The label for each epoch. | ||
If None not used. Defaults to None. | ||
|
||
Returns | ||
------- | ||
epochs_data : array, shape (n_epochs, n_channels, n_times) | ||
The original data | ||
""" | ||
if not isinstance(X, np.ndarray): | ||
raise ValueError("epochs_data should be of type ndarray (got %s)." | ||
% type(X)) | ||
|
||
return X.reshape(self.n_epochs, self.n_channels, self.n_times) | ||
|
||
|
||
class PSDEstimator(TransformerMixin): | ||
"""Compute power spectrum density (PSD) using a multi-taper method | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you just do:
in order to remove the old code of ConcatenateChannels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, @Eric89GXL fix removed.
It seems to pass docstring test.
Thanks @agramfort !