-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added eval_split() method to Base evaluation - issue #13: - Added evaluation tests On branch dev Changes to be committed: new file: .gitignore new file: .travis.yaml modified: aawedha/evaluation/base.py modified: aawedha/evaluation/cross_subject.py modified: aawedha/evaluation/single_subject.py modified: aawedha/io/base.py modified: aawedha/io/dummy.py modified: aawedha/models/EEGModels.py modified: requirements.txt new file: tests/evaluations_test.py
- Loading branch information
1 parent
bb28756
commit 03ec50d
Showing
10 changed files
with
173 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
dist/* | ||
build/* | ||
aawedha.egg-info | ||
# test-related | ||
.coverage | ||
.cache | ||
.pytest_cache | ||
|
||
# developer environments | ||
.idea | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: python | ||
|
||
python: | ||
- 3.6 | ||
|
||
before_install: | ||
- pip install -r requirements.txt | ||
|
||
install: | ||
- python setup.py install | ||
|
||
script: | ||
- pytest tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ numpy | |
pandas | ||
mne | ||
tensorflow | ||
keras | ||
tensorflow-addons | ||
scikit-learn | ||
scipy | ||
matplotlib | ||
seaborn | ||
pynvml | ||
pytest | ||
pynvml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pytest | ||
import tensorflow as tf | ||
import tensorflow.keras as keras | ||
|
||
from aawedha.io.dummy import Dummy | ||
from aawedha.evaluation.cross_subject import CrossSubject | ||
from aawedha.evaluation.single_subject import SingleSubject | ||
import numpy as np | ||
import random | ||
|
||
|
||
def seed(): | ||
tf.random.set_seed(42) | ||
np.random.seed(42) | ||
random.seed(42) | ||
|
||
|
||
def make_data(): | ||
data = Dummy(train_shape=(5, 500, 10, 100), test_shape=(5, 500, 10, 50), nb_classes=5) | ||
subjects, samples, channels, _ = data.epochs.shape | ||
n_classes = np.unique(data.y[0]).size | ||
return data, (subjects, samples, channels, n_classes) | ||
|
||
|
||
def make_model(channels, samples, n_classes): | ||
return keras.models.Sequential([ | ||
keras.Input(shape=(channels, samples, 1)), | ||
keras.layers.Conv2D(40, (1, 31)), | ||
keras.layers.Conv2D(40, (10, 1)), | ||
keras.layers.BatchNormalization(), | ||
keras.layers.Activation('elu'), | ||
keras.layers.AveragePooling2D(pool_size=(1, 35), strides=(1, 7)), | ||
keras.layers.Activation('elu'), | ||
keras.layers.Dropout(0.5), | ||
keras.layers.Flatten(), | ||
keras.layers.Dense(n_classes, activation='softmax')], | ||
name="dummy") | ||
|
||
|
||
def process_evaluation(evl, nfolds=4, strategy='Kfold', model=None): | ||
evl.generate_split(nfolds=nfolds, strategy=strategy) | ||
evl.set_model(model=model) | ||
evl.run_evaluation() | ||
return evl.results | ||
|
||
|
||
def test_single_subject(): | ||
# set seeds | ||
seed() | ||
# create random data | ||
data, shapes = make_data() | ||
subjects, samples, channels, n_classes = shapes | ||
# define en evaluation | ||
evl = SingleSubject(dataset=data, partition=[2, 1], verbose=0) | ||
# set model | ||
model = make_model(channels, samples, n_classes) | ||
results = process_evaluation(evl, nfolds=4, strategy='Stratified', model=model) | ||
# test value | ||
assert np.testing.assert_allclose(results['accuracy_mean'], 0.18, rtol=0.2) | ||
|
||
|
||
def test_cross_subject(): | ||
# set seeds | ||
seed() | ||
# create random data | ||
data, shapes = make_data() | ||
subjects, samples, channels, n_classes = shapes | ||
# define en evaluation | ||
evl = CrossSubject(dataset=data, partition=[4, 1], verbose=0) | ||
# set model | ||
model = make_model(channels, samples, n_classes) | ||
results = process_evaluation(evl, nfolds=1, strategy='Kfold', model=model) | ||
# test value | ||
assert np.testing.assert_allclose(results['accuracy_mean'], 0.2, rtol=0.2) | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main([__file__]) |