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

[ENH] Add auto information #112

Merged
merged 81 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
55b2ac7
Add autoinformation
vferat May 26, 2023
8d384ea
wip
vferat May 26, 2023
c04d488
wip
vferat May 26, 2023
6a44824
WIP
vferat May 27, 2023
bfa1615
Update autoinformation.py
vferat May 27, 2023
f06fd43
wip
vferat May 28, 2023
96c661d
Change entropy to use joint_entropy_history for easier maintenance
vferat May 28, 2023
5367867
Add ais, aif, paif
vferat May 30, 2023
ff68fb7
wip
vferat May 31, 2023
59b0817
[wip] Add excess_entropy_rate
vferat Jun 6, 2023
a588f84
WIP
vferat Aug 8, 2023
8361709
WIP
vferat Aug 8, 2023
0a3d036
WIP
vferat Aug 9, 2023
3e59e44
WIP
vferat Aug 9, 2023
957559d
Merge branch 'main' into dev-aifpaif
vferat Aug 9, 2023
52afbc4
Fix style
vferat Aug 9, 2023
d40340e
Add changes to changelog
vferat Aug 9, 2023
85699c1
Fix residuals
vferat Aug 9, 2023
7269ccc
WIP
vferat Aug 9, 2023
1967d0e
WIP
vferat Aug 9, 2023
c648257
WIP
vferat Aug 10, 2023
2d069de
Fix style
vferat Aug 10, 2023
d744148
fix style
vferat Aug 10, 2023
2d53cc8
Fix import
vferat Aug 10, 2023
06d0fb4
Fix docs (wip)
vferat Aug 10, 2023
8ec5e75
Fix style and docs
vferat Aug 10, 2023
6365421
Merge branch 'main' into dev-aifpaif
mscheltienne Aug 17, 2023
0b7d166
clean-up and fix type-hints in entropy
mscheltienne Aug 22, 2023
13e71e5
Update docs/source/dev/changes/latest.rst
vferat Sep 12, 2023
04865be
Update pycrostates/segmentation/_base.py
vferat Sep 12, 2023
7d616ce
Fix @mscheltienne review
vferat Sep 12, 2023
bd2f128
Update _typing.py
vferat Sep 12, 2023
7b8f55f
Update docs/source/dev/changes/latest.rst
vferat Sep 12, 2023
3109037
refractor public and private API
vferat Sep 12, 2023
fafc01c
Merge branch 'dev-aifpaif' of https://github.com/vferat/pycrostates i…
vferat Sep 12, 2023
ca123d1
Fix unused import
vferat Sep 12, 2023
69cbe0a
Fix bib file
vferat Sep 12, 2023
1a497df
Fix segmentation.entropy
vferat Sep 12, 2023
f3b9e1a
Fix docstring
vferat Sep 12, 2023
2f72ff5
Fix test name
vferat Sep 12, 2023
230a4e3
Fix footcite ?
vferat Sep 12, 2023
dad6a1a
Use :t: instead of :p:
mscheltienne Sep 12, 2023
7f8a898
Fix citation in autosummary
vferat Sep 13, 2023
ce4749d
Merge branch 'dev-aifpaif' of https://github.com/vferat/pycrostates i…
vferat Sep 13, 2023
eb85775
Change ignore_self to ignore_repetitions
vferat Sep 13, 2023
1f2f2b3
Add ignore_repetitions docstring
vferat Sep 13, 2023
8e1ddf7
Deprecate ignore_self in favour of ignore_repetitions
vferat Sep 13, 2023
8b491e9
Add test for deprecated
vferat Sep 13, 2023
f34471a
Fix style
vferat Sep 13, 2023
2e68617
Fix docs
vferat Sep 13, 2023
350773d
nitpick and typos
mscheltienne Oct 27, 2023
213584d
better deprecation
mscheltienne Oct 27, 2023
cd83f21
tutorial fixes
mscheltienne Oct 27, 2023
777f0c5
fix tutorial title
mscheltienne Oct 27, 2023
24b7462
Merge branch 'main' into dev-aifpaif
mscheltienne Oct 30, 2023
6f53265
Merge remote-tracking branch 'upstream/main' into dev-aifpaif
mscheltienne Nov 8, 2023
9f5cc5f
fix more
mscheltienne Nov 8, 2023
95cd822
fix ruff
mscheltienne Nov 8, 2023
78304ec
Merge remote-tracking branch 'upstream/main' into dev-aifpaif
mscheltienne Nov 8, 2023
3c72e6f
rm deprecation test function
mscheltienne Nov 8, 2023
c043df3
Merge remote-tracking branch 'upstream/main' into dev-aifpaif
mscheltienne Nov 10, 2023
643d7b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2024
1973447
Merge branch 'main' into dev-aifpaif
vferat Jan 31, 2024
5965b6b
Add state_to_ignore in docdict
vferat Jan 31, 2024
ca65ee4
Merge branch 'dev-aifpaif' of https://github.com/vferat/pycrostates i…
vferat Jan 31, 2024
722b20d
Add log_base and labels_info to docdict
vferat Jan 31, 2024
2b34e1c
Add segmentation to docdict
vferat Jan 31, 2024
ab7ac25
Dev aifpaif (#152)
Frederic-vW Feb 6, 2024
7d0582e
Merge remote-tracking branch 'upstream/main' into dev-aifpaif
mscheltienne Feb 6, 2024
9e5e8d5
rm file =61.0.0
mscheltienne Feb 6, 2024
438226e
better docstring format
mscheltienne Feb 6, 2024
d4f7d67
rm unused bibliographic item
mscheltienne Feb 6, 2024
9a23aa8
clean-up tutorial format
mscheltienne Feb 6, 2024
a1bbc6b
better documentation makefiles
mscheltienne Feb 6, 2024
7a2a9b5
a couple more clean-ups
mscheltienne Feb 6, 2024
49ff3fa
better documentation build configuration
mscheltienne Feb 6, 2024
1262ab8
fix missed
mscheltienne Feb 6, 2024
b71b7c9
fix dead links
mscheltienne Feb 6, 2024
d72ff4e
fix missed
mscheltienne Feb 6, 2024
127d836
Add optipng dependency
vferat Feb 13, 2024
bc9223b
Update .readthedocs.yaml
vferat Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ dmypy.json
# ----------------------------------------------------------------------------
.DS_Store
junit-results.xml
docs/source/sg_execution_times.rst
41 changes: 28 additions & 13 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXOPTS ?= -nWT --keep-going
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
.PHONY: help Makefile clean html html-noplot linkcheck linkcheck-grep view

first_target: help

help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " html-noplot to make standalone HTML files without plotting"
@echo " clean to clean HTML files"
@echo " linkcheck to check all external links for integrity"
@echo " linkcheck-grep to grep the linkcheck result"
@echo " view to view the built HTML"

html:
$(SPHINXBUILD) source build -b html $(SPHINXOPTS)

html-noplot:
$(SPHINXBUILD) source build -b html $(SPHINXOPTS) -D plot_gallery=0

clean:
rm -rf build source/generated source/api/generated

linkcheck:
$(SPHINXBUILD) source linkcheck -b linkcheck -D plot_gallery=0

.PHONY: help Makefile
linkcheck-grep:
@! grep -h "^.*:.*: \[\(\(local\)\|\(broken\)\)\]" linkcheck/output.txt

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
view:
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(PWD)/build/index.html')"
78 changes: 49 additions & 29 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
@ECHO OFF
@echo off

pushd %~dp0
REM Minimal makefile for Sphinx documentation

REM Command file for Sphinx documentation
REM Set default options and commands
set SPHINXOPTS=-nWT --keep-going
set SPHINXBUILD=sphinx-build

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
if "%1" == "html" goto html
if "%1" == "html-noplot" goto html-noplot
if "%1" == "clean" goto clean
if "%1" == "linkcheck" goto linkcheck
if "%1" == "linkcheck-grep" goto linkcheck-grep
if "%1" == "view" goto view

REM Define targets
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
echo Please use `make ^<target^>` where ^<target^> is one of
echo html to make standalone HTML files
echo html-noplot to make standalone HTML files without plotting
echo clean to clean HTML files
echo linkcheck to check all external links for integrity
echo linkcheck-grep to grep the linkcheck result
echo view to view the built HTML
goto :eof

:html
%SPHINXBUILD% source build -b html %SPHINXOPTS%
goto :eof

:html-noplot
%SPHINXBUILD% source build -b html %SPHINXOPTS% -D plot_gallery=0
goto :eof

:clean
rmdir /s /q build source\generated source\api\generated
goto :eof

:linkcheck
%SPHINXBUILD% source linkcheck -b linkcheck -D plot_gallery=0
goto :eof

:linkcheck-grep
findstr /C:"[broken]" linkcheck\output.txt > nul
if %errorlevel% equ 0 (
echo Lines with [broken]:
findstr /C:"[broken]" linkcheck\output.txt
) else (
echo No lines with [broken] found.
)
goto :eof

:end
popd
:view
python -c "import webbrowser; webbrowser.open_new_tab(r'file:///%cd%\build\index.html')"
goto :eof
29 changes: 29 additions & 0 deletions docs/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ @inproceedings{Roweis1997
year = {1997}
}

@article{shannon1948mathematical,
author = {Shannon, Claude E},
doi = {10.1002/j.1538-7305.1948.tb01338.x},
journal = {The Bell system technical journal},
number = {3},
pages = {379--423},
title = {A mathematical theory of communication},
volume = {27},
year = {1948}
}

@article{Silhouettes,
author = {Peter J. Rousseeuw},
doi = {10.1016/0377-0427(87)90125-7},
Expand All @@ -135,3 +146,21 @@ @article{Silhouettes
volume = {20},
year = {1987}
}

@article{von2018partial,
author = {Von Wegner, Frederic},
doi = {10.3389/fphys.2018.01382},
journal = {Frontiers in physiology},
pages = {1382},
title = {Partial autoinformation to characterize symbolic sequences},
volume = {9},
year = {2018}
}

@article{vonWegner2023,
author = {von Wegner, Frederic and Wiemers, Milena and Hermann, Gesine and T\"{o}dt, Inken and Tagliazucchi, Enzo and Laufs, Helmut},
doi = {10.1007/s10548-023-01006-2},
journal = {Brain Topography},
title = {Complexity Measures for EEG Microstate Sequences: Concepts and Algorithms},
year = {2023}
}
5 changes: 5 additions & 0 deletions docs/source/api/segmentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ Segmentation
EpochsSegmentation
compute_transition_matrix
compute_expected_transition_matrix
entropy
excess_entropy_rate
auto_information_function
partial_auto_information_function

20 changes: 18 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html


import subprocess
import sys
from datetime import date
from pathlib import Path
Expand Down Expand Up @@ -233,8 +233,18 @@
bibtex_bibfiles = ["../references.bib"]

# -- sphinx-gallery ----------------------------------------------------------
if sys.platform.startswith("win"):
try:
subprocess.check_call(["optipng", "--version"])
compress_images = ("images", "thumbnails")
except Exception:
compress_images = ()
else:
compress_images = ("images", "thumbnails")

sphinx_gallery_conf = {
"backreferences_dir": "generated/backreferences",
"compress_images": compress_images,
"doc_module": ("pycrostates",),
"examples_dirs": ["../../tutorials"],
"exclude_implicit_doc": {
Expand All @@ -244,7 +254,7 @@
"filename_pattern": r"\d{2}_",
"gallery_dirs": ["generated/auto_tutorials"],
"line_numbers": False, # messes with style
"plot_gallery": True,
"plot_gallery": "True", # str, to enable overwrite from CLI without warning
"reference_url": dict(pycrostates=None), # documented lib uses None
"remove_config_comments": True,
"show_memory": sys.platform == "linux",
Expand Down Expand Up @@ -281,3 +291,9 @@ def append_attr_meth_examples(app, what, name, obj, options, lines):
# -- sphinx_copybutton -----------------------------------------------------------------
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
copybutton_prompt_is_regexp = True

# -- linkcheck -------------------------------------------------------------------------
linkcheck_anchors = False # saves a bit of time
linkcheck_timeout = 15 # some can be quite slow
linkcheck_retries = 3
linkcheck_ignore = [] # will be compiled to regex
2 changes: 1 addition & 1 deletion docs/source/dev/changes/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Version 0.5
Enhancements
~~~~~~~~~~~~

- xxx
- Add :func:`~pycrostates.segmentation.entropy`, :func:`~pycrostates.segmentation.excess_entropy_rate`, :func:`~pycrostates.segmentation.auto_information_function` and :func:`~pycrostates.segmentation.partial_auto_information_function` (:pr:`112` by `Victor Férat`_ and `Frederic von Wegner`_)

Bugs
~~~~
Expand Down
2 changes: 2 additions & 0 deletions docs/source/dev/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.. _Mathieu Scheltienne: https://github.com/mscheltienne

.. _Reinmar Kobler: https://github.com/rkobler

.. _Frederic von Wegner: https://github.com/Frederic-vW
10 changes: 10 additions & 0 deletions pycrostates/segmentation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from .entropy import ( # noqa: F401
auto_information_function,
entropy,
excess_entropy_rate,
partial_auto_information_function,
)
from .segmentation import EpochsSegmentation, RawSegmentation # noqa: F401
from .transitions import ( # noqa: F401
compute_expected_transition_matrix,
Expand All @@ -7,6 +13,10 @@
__all__: tuple[str, ...] = (
"compute_expected_transition_matrix",
"compute_transition_matrix",
"entropy",
"excess_entropy_rate",
"auto_information_function",
"partial_auto_information_function",
"EpochsSegmentation",
"RawSegmentation",
)
48 changes: 42 additions & 6 deletions pycrostates/segmentation/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..utils._docs import fill_doc
from ..utils._logs import logger
from ..viz import plot_cluster_centers
from .entropy import entropy
from .transitions import _compute_expected_transition_matrix, _compute_transition_matrix


Expand Down Expand Up @@ -221,12 +222,15 @@ def compute_transition_matrix(self, stat="probability", ignore_repetitions=True)
-------
%(transition_matrix)s

Warnings
--------
When working with `~mne.Epochs`, this method will take into account transitions
that occur between epochs. This could lead to wrong interpretation when working
with discontinuous data. To avoid this behaviour, make sure to set the
``reject_edges`` parameter to ``True`` when predicting the segmentation.
Notes
-----
.. warning::

When working with `~mne.Epochs`, this method will take into account
transitions that occur between epochs. This could lead to wrong
interpretation when working with discontinuous data. To avoid this
behaviour, make sure to set the ``reject_edges`` parameter to ``True`` when
predicting the segmentation.
"""
return _compute_transition_matrix(
self._labels,
Expand Down Expand Up @@ -264,6 +268,38 @@ def compute_expected_transition_matrix(
ignore_repetitions=ignore_repetitions,
)

# Information ------------------------------------------------------------
@fill_doc
def entropy(
self,
ignore_repetitions: bool = False,
log_base: Union[float, str] = 2,
):
r"""Compute the Shannon entropy of the segmentation.

Compute the Shannon entropy\ :footcite:p:`shannon1948mathematical`
of the microstate symbolic sequence.

Parameters
----------
%(ignore_repetitions)s
%(log_base)s

Returns
-------
h : float
The Shannon entropy.

References
----------
.. footbibliography::
"""
return entropy(
self,
ignore_repetitions=ignore_repetitions,
log_base=log_base,
)

@fill_doc
def plot_cluster_centers(
self,
Expand Down
Loading
Loading