Skip to content

[WIP] Include alignment steps in coffeine pipeline - #58

Open
apmellot wants to merge 17 commits into
coffeine-labs:mainfrom
apmellot:transfer
Open

[WIP] Include alignment steps in coffeine pipeline#58
apmellot wants to merge 17 commits into
coffeine-labs:mainfrom
apmellot:transfer

Conversation

@apmellot

@apmellot apmellot commented Aug 1, 2023

Copy link
Copy Markdown
Collaborator

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

@agramfort agramfort left a comment

Copy link
Copy Markdown
Collaborator

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

Comment thread coffeine/transfer_learning.py Outdated
Parameters
----------
metric : str, default='riemann'
The metric to compute the mean.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Indent issue

Comment thread coffeine/transfer_learning.py Outdated
def __init__(self, domains, metric='riemann'):
self.domains = domains
self.metric = metric
self.re_center = TLCenter('target_domain', metric=self.metric)

Copy link
Copy Markdown
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

Comment thread coffeine/transfer_learning.py Outdated
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
Copy Markdown
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_

Comment thread coffeine/transfer_learning.py Outdated
self.metric = metric
self.re_scale = TLStretch('target_domain',
center_data=True,
metric=self.metric)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Idem

Comment thread coffeine/transfer_learning.py Outdated
y: ndarray, shape (n_matrices,)
Labels for each matrix.
domains: ndarray, shape (n_matrices,)
Domains for each matrix.

Copy link
Copy Markdown
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

Comment thread coffeine/transfer_learning.py Outdated
Apolline Mellot added 2 commits August 2, 2023 10:07
Comment thread coffeine/pipelines.py Outdated
else:
steps = [
projection(**projection_params_)
] + alignment_steps + [

Copy link
Copy Markdown
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.

Comment thread coffeine/pipelines.py Outdated
if 're-center' in alignment:
alignment_steps.append(ReCenter(domains=domains))
if 're-scale' in alignment:
alignment_steps.append(ReScale(domains=domains))

Copy link
Copy Markdown
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?

@apmellot apmellot Aug 3, 2023

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
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
Copy Markdown
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

dengemann commented Aug 2, 2023

Copy link
Copy Markdown
Collaborator

Some missing milestones:

  • unit tests
  • example

@apmellot

apmellot commented Aug 3, 2023

Copy link
Copy Markdown
Collaborator Author

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

@dengemann

Copy link
Copy Markdown
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

apmellot commented Aug 7, 2023

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
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