Skip to content

Commit

Permalink
MRG: Add ICA's fit_params to HTML representation (mne-tools#12194)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechenberger authored Nov 13, 2023
1 parent 7b3e3c9 commit 9cbdc7b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/changes/devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Enhancements
- Add support for passing multiple labels to :func:`mne.minimum_norm.source_induced_power` (:gh:`12026` by `Erica Peterson`_, `Eric Larson`_, and `Daniel McCloy`_ )
- Added documentation to :meth:`mne.io.Raw.set_montage` and :func:`mne.add_reference_channels` to specify that montages should be set after adding reference channels (:gh:`12160` by `Jacob Woessner`_)
- Add argument ``splash`` to the function using the ``qt`` browser backend to allow enabling/disabling the splash screen (:gh:`12185` by `Mathieu Scheltienne`_)
- :class:`~mne.preprocessing.ICA`'s HTML representation (displayed in Jupyter notebooks and :class:`mne.Report`) now includes all optional fit parameters (e.g., max. number of iterations) (:gh:`12194`, by `Richard Höchenberger`_)

Bugs
~~~~
Expand Down
4 changes: 4 additions & 0 deletions mne/html_templates/repr/ica.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<th>Method</th>
<td>{{ method }}</td>
</tr>
<tr>
<th>Fit parameters</th>
<td>{% if fit_params %}{% for key, value in fit_params.items() %}{{ key }}={{ value }}<br />{% endfor %}{% else %}&mdash;{% endif %}</td>
</tr>
<tr>
<th>Fit</th>
<td>{% if fit_on %}{{ n_iter }} iterations on {{ fit_on }} ({{ n_samples }} samples){% else %}no{% endif %}</td>
Expand Down
6 changes: 5 additions & 1 deletion mne/preprocessing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from inspect import Parameter, isfunction, signature
from numbers import Integral
from time import time
from typing import List, Literal, Optional
from typing import Dict, List, Literal, Optional, Union

import numpy as np
from scipy import linalg, stats
Expand Down Expand Up @@ -507,6 +507,7 @@ def _get_infos_for_repr(self):
class _InfosForRepr:
fit_on: Optional[Literal["raw data", "epochs"]]
fit_method: Literal["fastica", "infomax", "extended-infomax", "picard"]
fit_params: Dict[str, Union[str, float]]
fit_n_iter: Optional[int]
fit_n_samples: Optional[int]
fit_n_components: Optional[int]
Expand All @@ -522,6 +523,7 @@ class _InfosForRepr:
fit_on = "epochs"

fit_method = self.method
fit_params = self.fit_params
fit_n_iter = getattr(self, "n_iter_", None)
fit_n_samples = getattr(self, "n_samples_", None)
fit_n_components = getattr(self, "n_components_", None)
Expand All @@ -542,6 +544,7 @@ class _InfosForRepr:
infos_for_repr = _InfosForRepr(
fit_on=fit_on,
fit_method=fit_method,
fit_params=fit_params,
fit_n_iter=fit_n_iter,
fit_n_samples=fit_n_samples,
fit_n_components=fit_n_components,
Expand Down Expand Up @@ -576,6 +579,7 @@ def _repr_html_(self):
html = t.render(
fit_on=infos.fit_on,
method=infos.fit_method,
fit_params=infos.fit_params,
n_iter=infos.fit_n_iter,
n_samples=infos.fit_n_samples,
n_components=infos.fit_n_components,
Expand Down
1 change: 1 addition & 0 deletions mne/preprocessing/tests/test_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def test_ica_core(method, n_components, noise_cov, n_pca_components, browser_bac
repr_html_ = ica._repr_html_()
assert repr_ == f"<ICA | no decomposition, method: {method}>"
assert method in repr_html_
assert "max_iter=1" in repr_html_

# test fit checker
with pytest.raises(RuntimeError, match="No fit available"):
Expand Down

0 comments on commit 9cbdc7b

Please sign in to comment.