264 lines (264 with data), 6.3 kB
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "DeepEEG_Sim.ipynb",
"version": "0.3.2",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/kylemath/DeepEEG/blob/master/notebooks/DeepEEG_Sim.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cH7KRd8ZZPMd",
"colab_type": "text"
},
"source": [
"## DeepEEG\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "KjZu4dFMFHJV",
"colab_type": "code",
"colab": {}
},
"source": [
"!git clone https://github.com/kylemath/DeepEEG\n",
"!chmod +x ./DeepEEG/install.sh\n",
"%cd DeepEEG\n",
"!./install.sh\n",
"from utils import *\n",
"%matplotlib inline\n",
"%cd .."
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "FhkDPfIq1ewa",
"colab_type": "text"
},
"source": [
"#Simulate Data"
]
},
{
"cell_type": "code",
"metadata": {
"id": "jhU8hlcg1e6T",
"colab_type": "code",
"colab": {}
},
"source": [
"raw,event_id = SimulateRaw(amp1 = 50, amp2 = 5, freq = 2, batch = 2)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "AVBtNVebDtUc",
"colab_type": "text"
},
"source": [
"#Run Preprocessing\n",
"\n",
"**Input: mne.raw, event_id**\n",
"\n",
"**Output: mne.epochs**\n",
"```python\n",
"plot_psd=False\n",
"filter_data=True\n",
"eeg_filter_highpass=1\n",
"plot_events=False\n",
"epoch_time=(-.2,1)\n",
"baseline=(-.2,0)\n",
"rej_thresh_uV=200\n",
"rereference=False\n",
"emcp_raw=False\n",
"emcp_epochs=False\n",
"epoch_decim=1\n",
"plot_electrodes=False\n",
"plot_erp=False\n",
"```\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "RLIKMk6P453f",
"colab_type": "code",
"colab": {}
},
"source": [
"epochs = PreProcess(raw, event_id,filter_data=False,epoch_time = (-.2,1),plot_erp=True) \n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "iceVBB8vFxcr",
"colab_type": "text"
},
"source": [
"#Plot Features:\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "LqA4ZXaPFxkC",
"colab_type": "code",
"colab": {}
},
"source": [
"pick = 33 \n",
"#select electrode\n",
"for event in event_id.keys():\n",
" fig = plt.imshow(epochs[event]._data[:,pick,:])\n",
" plt.show()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "pwqD_voiDypa",
"colab_type": "text"
},
"source": [
"#Run FeatureEngineer\n",
"**Input: mne.epochs**\n",
"\n",
"**Output: deepeeg.feats**\n",
"```python\n",
"model_type='NN'\n",
"frequency_domain=False\n",
"normalization=True\n",
"electrode_median=False\n",
"wavelet_decim=1\n",
"flims=(3,30)\n",
"f_bins=20\n",
"wave_cycles=3\n",
"spect_baseline=[-1,-.5]\n",
"electrodes_out=[11,12,13,14,15]\n",
"test_split = 0.2\n",
"val_split = 0.2\n",
"random_seed=1017\n",
"watermark = False\n",
"```"
]
},
{
"cell_type": "code",
"metadata": {
"id": "i_jYlTW1A6sb",
"colab_type": "code",
"colab": {}
},
"source": [
"feats = FeatureEngineer(epochs, model_type = 'NN',\n",
" frequency_domain=True, \n",
" normalization= False,\n",
" flims=(5,20),spect_baseline=[-.5,0]\n",
" )"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "9ChMvr-jKp8P",
"colab_type": "text"
},
"source": [
"# Run CreateModel\n",
"\n",
"**Input: deepeeg.feats**\n",
"\n",
"**Output: deepeeg.model, deepeeg.encoder**\n",
"\n",
"```python\n",
"units=[16,8,4,8,16]\n",
"dropout=.25\n",
"batch_norm=True\n",
"filt_size=3\n",
"pool_size=2\n",
"```"
]
},
{
"cell_type": "code",
"metadata": {
"id": "HFf3rBbJKqHR",
"colab_type": "code",
"colab": {}
},
"source": [
"model, _ = CreateModel(feats, units=[512,512])"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "-EKBjSapfE4O",
"colab_type": "text"
},
"source": [
"# TrainTestVal\n",
"\n",
"**Input: deepEEG.model, deepEEG.feats**\n",
"\n",
"```python\n",
"batch_size=2\n",
"train_epochs=20\n",
"show_plots=True\n",
"```"
]
},
{
"cell_type": "code",
"metadata": {
"id": "u6ize7eJfB3J",
"colab_type": "code",
"colab": {}
},
"source": [
"TrainTestVal(model, feats)"
],
"execution_count": 0,
"outputs": []
}
]
}