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

Pseudo Online evaluation and dataset conversion #641

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f36291f
Pseudo Online evaluation and dataset conversion for BNCI2014001, BNCI…
carraraig Jul 29, 2024
a67b929
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 29, 2024
921f592
Updating whats new
carraraig Jul 29, 2024
0dcb68c
Update example
carraraig Jul 29, 2024
8f53345
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 29, 2024
adbeed7
Fix error
carraraig Jul 29, 2024
3d241aa
Merge remote-tracking branch 'origin/PseudoOnline' into PseudoOnline
carraraig Jul 29, 2024
3fb5949
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 29, 2024
406b36e
Fix error
carraraig Jul 29, 2024
7c1f4f5
Merge remote-tracking branch 'origin/PseudoOnline' into PseudoOnline
carraraig Jul 29, 2024
7a60fb1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 29, 2024
9be950f
Erro in Base Dataset
carraraig Jul 29, 2024
304fdda
Merge remote-tracking branch 'origin/PseudoOnline' into PseudoOnline
carraraig Jul 29, 2024
07dd9c8
Fix Bug
carraraig Jul 30, 2024
b2b7dda
Fix Bug
carraraig Jul 30, 2024
8e36d1f
Fix Bug
carraraig Jul 30, 2024
7e2c34c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 30, 2024
0641fc6
Reduce size of windows
carraraig Jul 30, 2024
9eface3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 30, 2024
d8f76ef
Reduce size parallel
carraraig Jul 30, 2024
8863fe0
Merge remote-tracking branch 'origin/PseudoOnline' into PseudoOnline
carraraig Jul 30, 2024
19e76f4
Merge branch 'develop' into PseudoOnline
bruAristimunha Oct 19, 2024
f4d63a2
Merge branch 'develop' into PseudoOnline
PierreGtch Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/source/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Develop branch

Enhancements
~~~~~~~~~~~~
- Increasing the version in the pre-commit config (:gh:`631` by pre-commit bot)
- Implementation of Pseudo Online framework (:gh:`641` by `Igor Carrara`_)

- Update version of pyRiemann to 0.7 (:gh:`671` by `Gregoire Cattan`_)

Expand Down Expand Up @@ -44,6 +46,7 @@ Enhancements
- Add new dataset :class:`moabb.datasets.Liu2024` dataset (:gh:`619` by `Taha Habib`_)



Bugs
~~~~
- Fix caching in the workflows (:gh:`632` by `Pierre Guetschel`_)
Expand Down
60 changes: 60 additions & 0 deletions examples/plot_pseudoonline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Set up the Directory for made it run on a server.

import numpy as np
from pyriemann.classification import MDM, FgMDM
from pyriemann.estimation import Covariances
from sklearn.pipeline import Pipeline

from moabb.datasets import BNCI2014_001
from moabb.evaluations import WithinSessionEvaluation
from moabb.paradigms import MotorImagery


sub = 1

# Initialize parameter for the Band Pass filter
fmin = 8
fmax = 30
tmax = 3

# Load Dataset and switch to Pseudoonline mode
dataset = BNCI2014_001()
dataset.pseudoonline = True

# events = ["right_hand", "left_hand"]
events = list(dataset.event_id.keys())

paradigm = MotorImagery(
events=events, n_classes=len(events), fmin=fmin, fmax=fmax, tmax=tmax, overlap=50
)

X, y, meta = paradigm.get_data(dataset=dataset, subjects=[sub])
print("Print Events_id:", y)
unique, counts = np.unique(y, return_counts=True)
print("Number of events per class:", dict(zip(unique, counts)))


pipelines = {}
pipelines["MDM"] = Pipeline(
steps=[
("Covariances", Covariances("cov")),
("MDM", MDM(metric=dict(mean="riemann", distance="riemann"))),
]
)

pipelines["FgMDM"] = Pipeline(
steps=[("Covariances", Covariances("cov")), ("FgMDM", FgMDM())]
)

dataset.subject_list = dataset.subject_list[int(sub) - 1 : int(sub)]
# Select an evaluation Within Session
evaluation_online = WithinSessionEvaluation(
paradigm=paradigm, datasets=dataset, overwrite=True, random_state=42, n_jobs=1
)

# Print the results
results_ALL = evaluation_online.process(pipelines)
results_pipeline = results_ALL.groupby(["pipeline"], as_index=False)["score"].mean()
results_pipeline_std = results_ALL.groupby(["pipeline"], as_index=False)["score"].std()
results_pipeline["std"] = results_pipeline_std["score"]
print(results_pipeline)
2 changes: 2 additions & 0 deletions moabb/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def __init__(
paradigm,
doi=None,
unit_factor=1e6,
overlap=False,
):
"""Initialize function for the BaseDataset."""
try:
Expand Down Expand Up @@ -348,6 +349,7 @@ def __init__(
self.paradigm = paradigm
self.doi = doi
self.unit_factor = unit_factor
self.overlap = overlap

def _create_process_pipeline(self):
return Pipeline(
Expand Down
Loading
Loading