Skip to content

[MRG] small ICA bug fixes for #5967 - 2nd try - #6246

Merged
mmagnuski merged 18 commits into
mne-tools:masterfrom
jeythekey:fix_ica-fixes2
May 3, 2019
Merged

mmagnuski merged 18 commits into
mne-tools:masterfrom
jeythekey:fix_ica-fixes2

Conversation

@jeythekey

Copy link
Copy Markdown
Contributor

Continues/replaces #5968

Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
@codecov

codecov Bot commented Apr 27, 2019 •

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@3d33e8e). Click here to learn what that means.
The diff coverage is 100%.

@@            Coverage Diff            @@
##             master    #6246   +/-   ##
=========================================
  Coverage          ?   89.24%           
=========================================
  Files             ?      416           
  Lines             ?    75418           
  Branches          ?    12597           
=========================================
  Hits              ?    67305           
  Misses            ?     5218           
  Partials          ?     2895

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

Did you also check why the unit tests were falling?

@jona-sassenhagen

jona-sassenhagen commented Apr 28, 2019 •

Copy link
Copy Markdown
Contributor

Very good, you only have a pep failure:

https://travis-ci.org/mne-tools/mne-python/jobs/525415877

mne/preprocessing/ica.py:2184:21: E126 continuation line over-indented for hanging indent

Fix that and set the title from FIX to MRG please.

@jeythekey jeythekey changed the title [FIX] small ICA bug fixes for #5967 - 2nd try [MRG] small ICA bug fixes for #5967 - 2nd try Apr 28, 2019
Comment thread doc/whats_new.rst Resolved
@jona-sassenhagen

Copy link
Copy Markdown
Contributor
/home/circleci/project/doc/whats_new.rst:210: WARNING: py:attr reference target not found: mne.preprocessing.ICA.exclude
/home/circleci/project/doc/whats_new.rst:212: WARNING: py:func reference target not found: mne.preprocessing.ICA.run_ica

@jeythekey

Copy link
Copy Markdown
Contributor Author

hm... and why? How to fix this? Is it important? run_ica is not part of the ICA class but in the same file. So how to link to this? Why it does not find the attribute I cannot see.

@larsoner

Copy link
Copy Markdown
Member

hm... and why? How to fix this?

You need to link to things where they are documented (implicitly or explicitly) in python_reference.rst, not where they end up in code. So the first one is mne.preprocessing.run_ica. The second one we actually can't link to without making it a @property rather than just variable, so for now instead of linking just use double backticks on it.

Is it important?

The way it is now, we will have broken links in our whats_new.html on the website.

@jeythekey

Copy link
Copy Markdown
Contributor Author

Thanks for the explanation. The first one was obvious, sorry ...

@larsoner

Copy link
Copy Markdown
Member

@mmagnuski if you use these functions can you take a look?

Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py
ecg_criterion=0.1, eog_ch=None,
eog_score_func='pearsonr',
eog_criterion=0.1, skew_criterion=-1,
kurt_criterion=-1, var_criterion=0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we change the default criteria here? This would change the behavior of detect_artifacts between versions without any warning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, my reasoning was that this way we at least actually keep the effect of the default values, because before this PR, [0] would index the lowest score and [-1] the highest, and know it is inverted (i.e. now it is as it is (and used to be) documented).

But you are right, it would be probably good to introduce a warning. Could you point me to a template for a warning about changing the behavior of a function? After all the bug is only in the incompatibility between documentation and code, so someone who knew the code and did not care about the docstring could be surprised ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The least surprise from a user perspective would be to keep the old behavior and old defaults, and update the docstring to say what this does.

If our old defaults made no sense, we can have a deprecation cycle where we set them to None for a cycle in the signature, and in 0.18 None does what was done in 0.17 (with a warning that not setting it explicitly will change in 0.19) and then in 0.19 we change the default to something sane.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @larsoner, BTW @jeythekey - you should better ask Eric about how to implement deprecations, I never did this so I would have to look around in our codebase, but Eric knows all this off the top of his head.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, in principle we would revert this PR and replace it with a warning, that in the next release the function will do what it used to say it would do in the docstring?
Is this really necessary in this case, where the docstring clearly states "Note. This is still experimental and will most likely change over the next releases."?
As it is now, at least the defaults will do the same as before (they were only changed, because of the bug-fix in the code), only when the criteria args used to be set contrary to what would be sensible given the docstring by a user, the behavior will change. So, this should only negatively affect those who dug through the code before, identified the bug and decided to silently adapt their usage instead of reporting the bug.

So, please, one last word by @larsoner: Should I really revert the fix for sorting the compos in descending order and replace the fix by a warning about a future fix?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, descending is good, it should be descending, so this is a bug fix. Then:

  • change the what's new to state that ascending was changed into descending. I read the "Fix descending sorting" as if it was descending and was changed.
  • I am ok with changing the criteria now, otherwise it would be nonsense. I somehow didn't before get that these "criteria" are indices. What do you think @larsoner? In case someone actually uses these we could set these to None and issue a warning.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In case someone actually uses these we could set these to None and issue a warning.

Even in this case if someone had previously passed values, now the behavior will be changed. I guess since the behavior is wrong and this is a bugfix, we can change the behavior like you say and make it clear in the BUG section that this has been fixed.

@agramfort are you okay with this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Even in this case if someone had previously passed values ...

Actually, only in this case ... (because the default values were inverted to retain the old behavior - and they make sense now, I guess, as they did before)

And what do you think about this warning (at the end) I tried to implement (with the wrong warning class, apparently)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@larsoner and @mmagnuski should I then just remove the warning? I changed the bug section as you suggested. Because then we should be good to go, or is there anything else, @agramfort ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes let's remove the warning if it's a bug. Then wait for @agramfort to comment next week to make sure it's reasonable

Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/tests/test_ica.py Resolved
@jeythekey

Copy link
Copy Markdown
Contributor Author

OK, I implemented your suggestion, thanks @mmagnuski. I also made the docstring a little more explicit.

To make the detect_artifacts method really useful, I think we need to (also) add the identified components to the .labels_ attribute as it is done in find_bads_eog/ecg rather than just dumping everything into .exclude, so the reason for labelling is logged. (There is also already a nice inspection function which makes use of .labels_.) Also, it would probably make sense if _detect_artifacts would call those functions internally for eog and ecg artifacts, e.g. to make use of the default filtering etc. --> Ideas for a next PR :)

Comment thread mne/preprocessing/ica.py Resolved
@jeythekey

Copy link
Copy Markdown
Contributor Author

OK, apparently, SyntaxWarning is the wrong class. What should it be instead? RuntimeWarning? I am not deprecating anything.

@agramfort agramfort left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dengemann wrote this I guess. I have no strong feeling. I discover this function :(
It's not present in any example or tutorial so I doubt this is very much used ...

Comment thread mne/preprocessing/ica.py Resolved
Comment thread mne/preprocessing/ica.py
def _apply_raw(self, raw, include, exclude, n_pca_components, start, stop):
"""Aux method."""
_check_preload(raw, "ica.apply")
exclude = self._check_exclude(exclude)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why removing all these calls to _check_exclude?

@jeythekey jeythekey May 2, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

... because this function is called in _pick_sources, which is called by all the apply_... funcs. Since _pick_sources does the exclude-relevant work I found it more consistent and future-proof to call _check_exclude there.

@agramfort

Copy link
Copy Markdown
Member

@mmagnuski or @larsoner merge if you're happy. Travis error is unrelated

@larsoner

larsoner commented May 3, 2019

Copy link
Copy Markdown
Member

I'll let you take a last look and merge if you're happy @mmagnuski

@mmagnuski

Copy link
Copy Markdown
Member

I'm happy, thanks @jeythekey!

@mmagnuski
mmagnuski merged commit 8ce77a0 into mne-tools:master May 3, 2019
@jeythekey
jeythekey deleted the fix_ica-fixes2 branch May 4, 2019 11:47
@GuillaumeFavelier

GuillaumeFavelier commented May 18, 2019 •

Copy link
Copy Markdown
Contributor

@jeythekey we don't have your name to update the mailing for the release. Can you provide us your full name and desired email to amend that? thx.

@jeythekey

Copy link
Copy Markdown
Contributor Author

@GuillaumeFavelier : Johannes Kasper, [email protected]

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.

6 participants