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

[WIP] Include alignment steps in coffeine pipeline #58

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

apmellot
Copy link
Collaborator

@apmellot apmellot commented Aug 1, 2023

For now, I only added the re-centering and the re-scaling step between projection and vectorization. I tested it with TUAB and LEMON and the results are as expected.
Next, I want to add the rotation correction step still using pyRiemann, create an example notebook and make nice docstrings.

@apmellot apmellot changed the title Include alignment steps in coffeine pipeline [WIP] Include alignment steps in coffeine pipeline Aug 1, 2023
Copy link
Collaborator

@agramfort agramfort left a comment

Choose a reason for hiding this comment

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

It seems tests are missing

Parameters
----------
metric : str, default='riemann'
The metric to compute the mean.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indent issue

def __init__(self, domains, metric='riemann'):
self.domains = domains
self.metric = metric
self.re_center = TLCenter('target_domain', metric=self.metric)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be put in the init

Init should just set the init parameters as attributes

def fit(self, X, y):
X = _check_data(X)
_, y_enc = encode_domains(X, y, self.domains)
self.means = self.re_center.fit(X, y_enc).recenter_
Copy link
Collaborator

Choose a reason for hiding this comment

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

re_center_ as it's set and modified in the fit

And means_

self.metric = metric
self.re_scale = TLStretch('target_domain',
center_data=True,
metric=self.metric)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idem

y: ndarray, shape (n_matrices,)
Labels for each matrix.
domains: ndarray, shape (n_matrices,)
Domains for each matrix.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Domains is not a param

coffeine/transfer_learning.py Outdated Show resolved Hide resolved
Apolline Mellot added 2 commits August 2, 2023 10:07
else:
steps = [
projection(**projection_params_)
] + alignment_steps + [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we be sure that this not buggy? We need to make sure that for every column (‘name’) independent instances are instantiated. Otherwise you risk some stateful behavior.

if 're-center' in alignment:
alignment_steps.append(ReCenter(domains=domains))
if 're-scale' in alignment:
alignment_steps.append(ReScale(domains=domains))
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment above. We would use the same ReCenter/ReScale instances for every column of the data frame based on this code here, right?

Copy link
Collaborator Author

@apmellot apmellot Aug 3, 2023

Choose a reason for hiding this comment

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

I don't understand, isn't it the same thing as what is done a few lines above for the projection and vectorization steps?
Also in practice I checked and each frequency band is aligned independently.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It’s not the same as we instantiate the classes independently for every column. We can check of course if this is practically unneccessary by now because of internal cloning etc. But if you want to be consistent with the tested / save code you can just adopt the same pattern as for the other projection/vectorization steps. You currently instantiate the classes globally and plug in the same input column by column.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok I see, let's do it as projection/vectorization.

@dengemann
Copy link
Collaborator

dengemann commented Aug 2, 2023

Some missing milestones:

  • unit tests
  • example

@apmellot
Copy link
Collaborator Author

apmellot commented Aug 3, 2023

Test failing is related to this issue in pyRiemann: pyRiemann/pyRiemann#257

@dengemann
Copy link
Collaborator

Test failing is related to this issue in pyRiemann: pyRiemann/pyRiemann#257

@apmellot what’s your philosophy here? Fixing it in PyRiemann and waiting for that? Implementing a patch locally and then use PyRiemann in the future once it is fixed there?

@apmellot
Copy link
Collaborator Author

apmellot commented Aug 7, 2023

Test failing is related to this issue in pyRiemann: pyRiemann/pyRiemann#257

@apmellot what’s your philosophy here? Fixing it in PyRiemann and waiting for that? Implementing a patch locally and then use PyRiemann in the future once it is fixed there?

The PR is open in pyRiemann, we can wait for it to be merged.

@dengemann
Copy link
Collaborator

We will need a patch to support earlier versions of PyRiemann - otherwise we depend on master branch. We can add a checker that sees the pyriemann version and depending on the version supplies our patched function or uses the upstream one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants