Skip to content
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

Improving feature names #42

Merged
merged 6 commits into from
Sep 28, 2018
36 changes: 36 additions & 0 deletions mne_features/tests/test_univariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np
from numpy.testing import assert_equal, assert_almost_equal, assert_raises

from mne_features.feature_extraction import extract_features
from mne_features.univariate import (_slope_lstsq, _accumulate_std,
_accumulate_min, _accumulate_max,
compute_mean, compute_variance,
Expand Down Expand Up @@ -178,6 +179,40 @@ def test_pow_freq_bands():
ratios='only'), expected_ratios)


def test_feature_names_pow_freq_bands():
_data = data[:, :3, :] # keep only 3 channels for the sake of simplicity
selected_funcs = ['pow_freq_bands']
fb = np.array([[4., 8.], [30., 70.]])
ratios_col_names = ['ch0_0_1', 'ch0_1_0', 'ch1_0_1', 'ch1_1_0',
'ch2_0_1', 'ch2_1_0']
pow_col_names = ['ch0_0', 'ch0_1', 'ch1_0', 'ch1_1', 'ch2_0', 'ch2_1']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no way to have more explicit names likes alpha, beta etc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could improve that but, at some point, the user would need to name the frequency bands he wishes to use. What about allowing the freq_bands parameter in compute_pow_freq_bands to be a dict as the one below?

freq_bands = {'delta': [0.5, 4], 
              'theta': [4, 8], 
              'alpha': [8, 13], 
              'beta': [13, 30], 
              'low-gamma': [30, 70], 
              'high-gamma': [70, 100]}


# With `ratios = 'only'`:
df_only = extract_features(
_data, sfreq, selected_funcs,
funcs_params={'pow_freq_bands__ratios': 'only',
'pow_freq_bands__freq_bands': fb},
return_as_df=True)
assert_equal(df_only.columns.get_level_values(1).values, ratios_col_names)

# With `ratios = 'all'`:
df_all = extract_features(
_data, sfreq, selected_funcs,
funcs_params={'pow_freq_bands__ratios': 'all',
'pow_freq_bands__freq_bands': fb},
return_as_df=True)
assert_equal(df_all.columns.get_level_values(1).values,
pow_col_names + ratios_col_names)

# With `ratios = None`:
df = extract_features(
_data, sfreq, selected_funcs,
funcs_params={'pow_freq_bands__ratios': None,
'pow_freq_bands__freq_bands': fb},
return_as_df=True)
assert_equal(df.columns.get_level_values(1).values, pow_col_names)


def test_hjorth_mobility_spect():
expected = 0.005 * (5 ** 2) + 0.00125 * (33 ** 2)
assert_almost_equal(compute_hjorth_mobility_spect(sfreq, data_sin),
Expand Down Expand Up @@ -368,6 +403,7 @@ def test_shape_output_teager_kaiser_energy():
test_samp_entropy()
test_decorr_time()
test_pow_freq_bands()
test_feature_names_pow_freq_bands()
test_hjorth_mobility_spect()
test_hjorth_complexity_spect()
test_hjorth_mobility()
Expand Down