Skip to content

[MRG] Improve ICA docstring - #5114

Merged
agramfort merged 11 commits into
mne-tools:masterfrom
cbrnr:ica_docstring
Apr 19, 2018
Merged

agramfort merged 11 commits into
mne-tools:masterfrom
cbrnr:ica_docstring

Conversation

@cbrnr

@cbrnr cbrnr commented Apr 11, 2018

Copy link
Copy Markdown
Contributor

Fixes #4882.

@codecov

codecov Bot commented Apr 11, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5114 into master will increase coverage by 0.03%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #5114      +/-   ##
==========================================
+ Coverage   88.14%   88.17%   +0.03%     
==========================================
  Files         356      358       +2     
  Lines       65774    65899     +125     
  Branches    11193    11203      +10     
==========================================
+ Hits        57978    58108     +130     
+ Misses       4959     4956       -3     
+ Partials     2837     2835       -2

@cbrnr

cbrnr commented Apr 11, 2018

Copy link
Copy Markdown
Contributor Author

Quick question, what do the numbers (1, 2) mean before each reference in the list?
https://7696-1301584-gh.circle-artifacts.com/0/html/generated/mne.preprocessing.ICA.html#mne.preprocessing.ICA

Also, shouldn't the reference list be at the very end of the description? Currently, they are placed right after the parameters, before the attributes.

@agramfort

agramfort commented Apr 11, 2018 via email

Copy link
Copy Markdown
Member

@agramfort

agramfort commented Apr 11, 2018 via email

Copy link
Copy Markdown
Member

@larsoner

Copy link
Copy Markdown
Member

In the code it looks like the refs are below Attributes:

https://github.com/mne-tools/mne-python/blob/master/mne/preprocessing/ica.py#L201

I have no idea how it ends up above Attributes. It makes me think I'm looking at the wrong line, as I'm not sure what could cause this.

@cbrnr

cbrnr commented Apr 11, 2018

Copy link
Copy Markdown
Contributor Author

@agramfort each ref is only mentioned once. 1 seems to take me to the right place, but 2 doesn't point anywhere...

@agramfort

agramfort commented Apr 11, 2018 via email

Copy link
Copy Markdown
Member

@cbrnr

cbrnr commented Apr 11, 2018

Copy link
Copy Markdown
Contributor Author

@larsoner I think you're looking at the right lines. Maybe this is a Sphinx setting? It's not specific to this class.

@cbrnr

cbrnr commented Apr 11, 2018

Copy link
Copy Markdown
Contributor Author

I've created a separate issue #5118 for these docs issues. Let's focus on improving the ICA docs here.

@cbrnr

cbrnr commented Apr 11, 2018

Copy link
Copy Markdown
Contributor Author

@agramfort regarding the shapes, do you really want me to add this information for all attributes? I agree that this would be nice, but the shape of e.g. the unmixing matrix depends on specific parameters (e.g. whether you're using n_components or max_pca_components). I suggest that we take care of this in #4856 after we've clarified all of these issues.

@cbrnr cbrnr changed the title [WIP] Improve ICA docstring [MRG] Improve ICA docstring Apr 11, 2018
Comment thread mne/preprocessing/ica.py Outdated
pca_components_ : ndarray
If fit, the PCA components
``pca_mean_`` : ndarray
pca_mean_ : ndarray

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 really think you should document the shapes using n_channels and the other attributes such as n_components_

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.

Can we do that in #4856?

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 think it's okay to postpone the shape stuff until we fully tackle the full description of operations, which is indeed covered by #4856 (this one can just fix some minor issues incrementally).

Now that #5120 is merged, can you rebase this one @cbrnr then we can merge?

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.

Done.

Comment thread mne/preprocessing/ica.py
References
----------
.. [1] Hyvarinen, A., 1999. Fast and robust fixed-point algorithms for
.. [1] Hyvärinen, A., 1999. Fast and robust fixed-point algorithms for

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.

This might necessitate using u""" above

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.

😡 Python 2 💣

Comment thread mne/preprocessing/ica.py Outdated
The number of components used for PCA dimensionality reduction.
verbose : bool, str, int, or None
See above.
pre_whitener_ : ndarray

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.

you really don't want to add the shapes here?

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.

I do want to add the shapes eventually, I was just saying that this might be better implemented in #4856 once we've sorted out all open issues there. However, if you insist I can also add them here. Let me know.

@agramfort

agramfort commented Apr 13, 2018 via email

Copy link
Copy Markdown
Member

@cbrnr

cbrnr commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

OK, I will do this tomorrow!

@cbrnr

cbrnr commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

I did some more spring cleaning, please review if these changes are OK. I've also added shapes for ndarrays. Some things are still unclear, especially everything related to the n_components, max_pca_components, and n_pca_components parameters and related attributes, but this will be tackled in #4856.

However, I'd like to address the following open issues here:

  1. The text for n_pca_components talks about .pick_sources_raw and .pick_sources_epochs methods. However, these methods don't exist. I suggest that we remove this text and then clarify the rest in ICA arguments confusion #4856.
  2. Same for the exclude attribute, where a pick_sources method is mentioned, which doesn't exist.
  3. Does the list of attributes need to contain all parameters? I always assumed that it is sufficient to list only additional attributes that are not also parameters.

Other more general things to discuss:

  1. I really suggest to use single backticks for argument names in the docstrings as per the numpydoc style guide. Double backticks should be reserved for code (examples).
  2. When do we append an underscore to an attribute name? In the ICA docstring, why does e.g. current_fit have no underscore, but e.g. n_samples_ does have one?

@cbrnr

cbrnr commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

OK, and now we have the problem that Sphinx renders things with underscores as links. I tried to escape them with backslashes, but it doesn't seem to work (unless raw strings do the trick, but I doubt that). Any ideas? It works fine in the parameters list, but not in the attributes: https://7784-1301584-gh.circle-artifacts.com/0/html/generated/mne.preprocessing.ICA.html#mne.preprocessing.ICA

@larsoner

Copy link
Copy Markdown
Member

The linked attributes list looks okay, where should I see the problem? I also don't see any related warnings in the CircleCI build.

@cbrnr

cbrnr commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

Now I added a backslash, which doesn't work:

screen shot 2018-04-18 at 15 51 10

Without the backslash, these occurrences are rendered as links (to nothing).

@larsoner

Copy link
Copy Markdown
Member

If you like how scores renders in Returns of this docstring:

https://7784-1301584-gh.circle-artifacts.com/0/html/generated/mne.preprocessing.ICA.html#mne.preprocessing.ICA.find_bads_ecg

it uses

scores : np.ndarray of float, shape (``n_components_``)

You might also be able to get away with single-backticks if you want to keep the italic formatting

@cbrnr

cbrnr commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

OK, single backticks work and look better than double backticks.

@cbrnr

cbrnr commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

In addition to my questions above, there's one more thing I don't understand: why is the __hash__ method listed for the ICA class?

@larsoner

Copy link
Copy Markdown
Member

@cbrnr

cbrnr commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

Where is the __hash__ method added to the ICA class? I only see the inherited method, which just contains a pass statement.

@larsoner

Copy link
Copy Markdown
Member

I don't know actually. Maybe there is some built-in hash function

Comment thread mne/preprocessing/ica.py Outdated
The number of components used for PCA decomposition. If None, no
dimension reduction will be applied and max_pca_components will equal
the number of channels supplied on decomposing data. Defaults to None.
dimension reduction will be applied and `max_pca_components` will equal

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.

dimensionality

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.

Done.

Comment thread mne/preprocessing/ica.py
Infomax and Picard differ, making it hard to compare different
tolerance levels, but a rule of thumb is
`tol_fastica = tol_picard ** 2`. Reducing the tolerance speeds up
estimation but the consistency of the obtained results decreases.

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.

This comment on Picard must have been recent. Why is it not good?

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 think it's in Notes now

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.

Yes, I think this comment is too specific for the ICA docstring.

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.

sorry but I don't see the comment anywhere. Do I miss something?

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 just looked and I can't find it either! @cbrnr can you move this to the Notes section

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.

Notes of the ICA class (if it doesn't exist, add it)

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.

OK, I'll create one, but is anyone up to rephrasing it? I think Picard is more or less an Extended FastICA, so I'm not sure if the tolarance can really be compared with Infomax?

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.

Reducing the tolerance speeds up estimation at the cost of consistency of the obtained results. It is difficult to directly compare tolerance levels between Infomax and Picard, but for Picard and FastICA a good rule of thumb is tol_fastica = tol_picard ** 2.

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.

Thanks, I like it! Moving that to the Notes section.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good to me as well!

@dengemann

Copy link
Copy Markdown
Member

Looks good otherwise. Thank you Clemens!

@cbrnr

cbrnr commented Apr 19, 2018

Copy link
Copy Markdown
Contributor Author

@larsoner is an ICA object immutable? If not, it shouldn't be hashable. I have no idea why it is either. But I can type ica.__hash__() and I get some number back. Should we set a class attribute __hash__ = None to prevent this?

Do you have time to help me with these open questions concerning the ICA docstring? I'd like to fix this for this PR.

  1. The text for n_pca_components talks about .pick_sources_raw and .pick_sources_epochs methods. However, these methods don't exist. I suggest that we remove this text and then clarify the rest in ICA arguments confusion #4856.
  2. Same for the exclude attribute, where a pick_sources method is mentioned, which doesn't exist.
  3. Does the list of attributes need to contain all parameters? I always assumed that it is sufficient to list only additional attributes that are not also parameters.
  4. When do we append an underscore to an attribute name? In the ICA docstring, why does e.g. current_fit have no underscore, but e.g. n_samples_ does have one?

@agramfort

Copy link
Copy Markdown
Member

@cbrnr we put underscore in attributes of object when they appear during the fit as they are data dependant. It's the sklearn convention.

ok to remove references to methods that have been removed.

@cbrnr tell me when ready to merge.

@larsoner

Copy link
Copy Markdown
Member

I don't think we are consistent about all attributes being shown. In principle, though, not all parameters passed to the class constructor will be turned into attributes (they can be stored privately or used immediately to make some other var instead), so it might be a good idea to list them if they do turn into attributes. I'm fine with it either way

@larsoner

Copy link
Copy Markdown
Member

As far as __hash__ = None let's not hold this up for it but do it separately if someone is motivated. I'd assume YAGNI for it being needed or a problem for now

@cbrnr

cbrnr commented Apr 19, 2018

Copy link
Copy Markdown
Contributor Author

@larsoner it's just weird that __hash__ shows up in the documentation. But yeah, if it keeps bothering me I'll tackle it separately.

@cbrnr

cbrnr commented Apr 19, 2018

Copy link
Copy Markdown
Contributor Author

OK, if CIs are happy this is ready to merge. I'll leave the list of attributes without the parameters for now because it is a bit redundant. But of course you are right, __init__ parameters don't have to be turned into attributes, but I guess people will find their description anyway.

@agramfort
agramfort merged commit 1a09859 into mne-tools:master Apr 19, 2018
@agramfort

Copy link
Copy Markdown
Member

thx @cbrnr

britta-wstnr pushed a commit to britta-wstnr/mne-python that referenced this pull request Jul 5, 2018
* Docstring cosmetics; rename _pre_whitener to pre_whitener_

* Add pre_whitener_ to list of attributes

* Rename all _pre_whitener -> pre_whitener_

* Update tests

* Fix Python 2 encoding issue

* Unicode str for Python 2

* Cleanup and add shapes

* Escape training underscores

* Try single backticks

* dimension -> dimensionality

* Move Picard comment to Notes section, remove refs to non-existing methods
@cbrnr
cbrnr deleted the ica_docstring branch July 10, 2018 11:48
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.

5 participants