-
-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #739 from neuropsychology/add_microstates_example
[Example] Add microstates analysis example
- Loading branch information
Showing
10 changed files
with
939 additions
and
77 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
import pandas as pd | ||
from ..misc import as_vector | ||
|
||
from ..complexity import entropy_shannon | ||
from ..misc import as_vector | ||
|
||
|
||
def microstates_complexity(microstates, show=False): | ||
"""**Complexity of Microstates Pattern** | ||
This computes the complexity related to the sequence of the microstates pattern. | ||
.. note:: | ||
def microstates_complexity(microstates): | ||
"""Complexity of microstates pattern | ||
This function does not compute all the features available under the complexity | ||
submodule. Don't hesitate to open an issue to help us test and decide what features to | ||
include. | ||
Parameters | ||
---------- | ||
microstates : np.ndarray | ||
The topographic maps of the found unique microstates which has a shape of n_channels x | ||
n_states, generated from :func:`.nk.microstates_segment`. | ||
show : bool | ||
Show the transition matrix. | ||
See Also | ||
-------- | ||
.microstates_dynamic, .microstates_static | ||
Examples | ||
-------- | ||
.. ipython:: python | ||
import neurokit2 as nk | ||
microstates = [0, 0, 0, 1, 1, 2, 2, 2, 2, 1, 0, 0, 2, 2] | ||
@savefig p_microstates_complexity1.png scale=100% | ||
nk.microstates_complexity(microstates, show=True) | ||
@suppress | ||
plt.close() | ||
""" | ||
# Try retrieving info | ||
if isinstance(microstates, dict): | ||
microstates = microstates["Sequence"] | ||
# Sanitize | ||
microstates = as_vector(microstates) | ||
|
||
# Initialize output container | ||
out = {} | ||
|
||
# Empirical Shannon entropy | ||
out["Entropy_Shannon"] = entropy_shannon(microstates) | ||
out["Entropy_Shannon"], _ = entropy_shannon(microstates, show=show) | ||
|
||
# Maximym entropy given the number of different states | ||
# h_max = np.log2(len(np.unique(microstates))) | ||
# h_max = np.log2(len(np.unique(microstates))) | ||
|
||
df = pd.DataFrame.from_dict(out, orient="index").T.add_prefix("Microstate_") | ||
df = pd.DataFrame.from_dict(out, orient="index").T.add_prefix("Microstates_") | ||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.