{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The Unitary Events Analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The executed version of this tutorial is at https://elephant.readthedocs.io/en/latest/tutorials/unitary_event_analysis.html\n", "\n", "The Unitary Events (UE) analysis \\[1\\] tool allows us to reliably detect correlated spiking activity that is not explained by the firing rates of the neurons alone. It was designed to detect coordinated spiking activity that occurs significantly more often than predicted by the firing rates of the neurons. The method allows one to analyze correlations not only between pairs of neurons but also between multiple neurons, by considering the various spike patterns across the neurons. In addition, the method allows one to extract the dynamics of correlation between the neurons by perform-ing the analysis in a time-resolved manner. This enables us to relate the occurrence of spike synchrony to behavior.\n", "\n", "The algorithm:\n", "\n", "1. Align trials, decide on width of analysis window.\n", "2. Decide on allowed coincidence width.\n", "3. Perform a sliding window analysis. In each window:\n", " 1. Detect and count coincidences.\n", " 2. Calculate expected number of coincidences.\n", " 3. Evaluate significance of detected coincidences.\n", " 4. If significant, the window contains Unitary Events.\n", "4. Explore behavioral relevance of UE epochs.\n", "\n", "References:\n", "\n", "1. GrĂ¼n, S., Diesmann, M., Grammont, F., Riehle, A., & Aertsen, A. (1999). Detecting unitary events without discretization of time. Journal of neuroscience methods, 94(1), 67-79." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import random\n", "import matplotlib.pyplot as plt\n", "import quantities as pq\n", "\n", "import elephant.unitary_event_analysis as ue\n", "from elephant.datasets import load_data\n", "from viziphant.unitary_event_analysis import plot_ue\n", "\n", "# Fix random seed to guarantee fixed output\n", "random.seed(1224)\n", "\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load data and extract spiketrains" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, we load the data with the spiking activity of 2 neurons across 36 trials. \n", "\n", "The spike trains are stored in a dataset saved with the NIX file format. The data in the NIX file is represented as a `neo.Block` containing 36 `neo.Segment`s, one for each trial. The `neo.Segment` contains 2 `neo.SpikeTrain` objects, each corresponding to the activity of one neuron in the trial.\n", "\n", "The NIX file will be automatically downloaded from https://datasets.python-elephant.org and the spiking activity data loaded into the variable `spiketrains`. This variable will store the trial data as a list of lists, where each of the 36 inner lists contains the `neo.SpikeTrain` objects with the activity of both neurons in a single trial.\n", "\n", "For more information on `neo.Block`, `neo.Segment`, and `neo.SpikeTrain` refer to https://neo.readthedocs.io/en/stable/api_reference.html." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "spiketrains = load_data('unitary_events')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Calculate Unitary Events" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "UE = ue.jointJ_window_analysis(\n", " spiketrains, bin_size=5*pq.ms, win_size=100*pq.ms, win_step=10*pq.ms, pattern_hash=[3])\n", "\n", "plot_ue(spiketrains, UE, significance_level=0.05)\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.23" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "toc": { "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }