Switch to unified view

a b/notebooks/DeepEEG_Sim.ipynb
1
{
2
  "nbformat": 4,
3
  "nbformat_minor": 0,
4
  "metadata": {
5
    "colab": {
6
      "name": "DeepEEG_Sim.ipynb",
7
      "version": "0.3.2",
8
      "provenance": [],
9
      "include_colab_link": true
10
    },
11
    "kernelspec": {
12
      "name": "python3",
13
      "display_name": "Python 3"
14
    },
15
    "accelerator": "GPU"
16
  },
17
  "cells": [
18
    {
19
      "cell_type": "markdown",
20
      "metadata": {
21
        "id": "view-in-github",
22
        "colab_type": "text"
23
      },
24
      "source": [
25
        "<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>"
26
      ]
27
    },
28
    {
29
      "cell_type": "markdown",
30
      "metadata": {
31
        "id": "cH7KRd8ZZPMd",
32
        "colab_type": "text"
33
      },
34
      "source": [
35
        "## DeepEEG\n"
36
      ]
37
    },
38
    {
39
      "cell_type": "code",
40
      "metadata": {
41
        "id": "KjZu4dFMFHJV",
42
        "colab_type": "code",
43
        "colab": {}
44
      },
45
      "source": [
46
        "!git clone https://github.com/kylemath/DeepEEG\n",
47
        "!chmod +x ./DeepEEG/install.sh\n",
48
        "%cd DeepEEG\n",
49
        "!./install.sh\n",
50
        "from utils import *\n",
51
        "%matplotlib inline\n",
52
        "%cd .."
53
      ],
54
      "execution_count": 0,
55
      "outputs": []
56
    },
57
    {
58
      "cell_type": "markdown",
59
      "metadata": {
60
        "id": "FhkDPfIq1ewa",
61
        "colab_type": "text"
62
      },
63
      "source": [
64
        "#Simulate Data"
65
      ]
66
    },
67
    {
68
      "cell_type": "code",
69
      "metadata": {
70
        "id": "jhU8hlcg1e6T",
71
        "colab_type": "code",
72
        "colab": {}
73
      },
74
      "source": [
75
        "raw,event_id = SimulateRaw(amp1 = 50, amp2 = 5, freq = 2, batch = 2)"
76
      ],
77
      "execution_count": 0,
78
      "outputs": []
79
    },
80
    {
81
      "cell_type": "markdown",
82
      "metadata": {
83
        "id": "AVBtNVebDtUc",
84
        "colab_type": "text"
85
      },
86
      "source": [
87
        "#Run Preprocessing\n",
88
        "\n",
89
        "**Input:  mne.raw, event_id**\n",
90
        "\n",
91
        "**Output: mne.epochs**\n",
92
        "```python\n",
93
        "plot_psd=False\n",
94
        "filter_data=True\n",
95
        "eeg_filter_highpass=1\n",
96
        "plot_events=False\n",
97
        "epoch_time=(-.2,1)\n",
98
        "baseline=(-.2,0)\n",
99
        "rej_thresh_uV=200\n",
100
        "rereference=False\n",
101
        "emcp_raw=False\n",
102
        "emcp_epochs=False\n",
103
        "epoch_decim=1\n",
104
        "plot_electrodes=False\n",
105
        "plot_erp=False\n",
106
        "```\n",
107
        "\n",
108
        "\n"
109
      ]
110
    },
111
    {
112
      "cell_type": "code",
113
      "metadata": {
114
        "id": "RLIKMk6P453f",
115
        "colab_type": "code",
116
        "colab": {}
117
      },
118
      "source": [
119
        "epochs = PreProcess(raw, event_id,filter_data=False,epoch_time = (-.2,1),plot_erp=True)                \n"
120
      ],
121
      "execution_count": 0,
122
      "outputs": []
123
    },
124
    {
125
      "cell_type": "markdown",
126
      "metadata": {
127
        "id": "iceVBB8vFxcr",
128
        "colab_type": "text"
129
      },
130
      "source": [
131
        "#Plot Features:\n"
132
      ]
133
    },
134
    {
135
      "cell_type": "code",
136
      "metadata": {
137
        "id": "LqA4ZXaPFxkC",
138
        "colab_type": "code",
139
        "colab": {}
140
      },
141
      "source": [
142
        "pick = 33 \n",
143
        "#select electrode\n",
144
        "for event in event_id.keys():\n",
145
        "  fig = plt.imshow(epochs[event]._data[:,pick,:])\n",
146
        "  plt.show()"
147
      ],
148
      "execution_count": 0,
149
      "outputs": []
150
    },
151
    {
152
      "cell_type": "markdown",
153
      "metadata": {
154
        "id": "pwqD_voiDypa",
155
        "colab_type": "text"
156
      },
157
      "source": [
158
        "#Run FeatureEngineer\n",
159
        "**Input:  mne.epochs**\n",
160
        "\n",
161
        "**Output: deepeeg.feats**\n",
162
        "```python\n",
163
        "model_type='NN'\n",
164
        "frequency_domain=False\n",
165
        "normalization=True\n",
166
        "electrode_median=False\n",
167
        "wavelet_decim=1\n",
168
        "flims=(3,30)\n",
169
        "f_bins=20\n",
170
        "wave_cycles=3\n",
171
        "spect_baseline=[-1,-.5]\n",
172
        "electrodes_out=[11,12,13,14,15]\n",
173
        "test_split = 0.2\n",
174
        "val_split = 0.2\n",
175
        "random_seed=1017\n",
176
        "watermark = False\n",
177
        "```"
178
      ]
179
    },
180
    {
181
      "cell_type": "code",
182
      "metadata": {
183
        "id": "i_jYlTW1A6sb",
184
        "colab_type": "code",
185
        "colab": {}
186
      },
187
      "source": [
188
        "feats = FeatureEngineer(epochs, model_type = 'NN',\n",
189
        "                        frequency_domain=True, \n",
190
        "                        normalization= False,\n",
191
        "                        flims=(5,20),spect_baseline=[-.5,0]\n",
192
        "                        )"
193
      ],
194
      "execution_count": 0,
195
      "outputs": []
196
    },
197
    {
198
      "cell_type": "markdown",
199
      "metadata": {
200
        "id": "9ChMvr-jKp8P",
201
        "colab_type": "text"
202
      },
203
      "source": [
204
        "# Run CreateModel\n",
205
        "\n",
206
        "**Input: deepeeg.feats**\n",
207
        "\n",
208
        "**Output: deepeeg.model, deepeeg.encoder**\n",
209
        "\n",
210
        "```python\n",
211
        "units=[16,8,4,8,16]\n",
212
        "dropout=.25\n",
213
        "batch_norm=True\n",
214
        "filt_size=3\n",
215
        "pool_size=2\n",
216
        "```"
217
      ]
218
    },
219
    {
220
      "cell_type": "code",
221
      "metadata": {
222
        "id": "HFf3rBbJKqHR",
223
        "colab_type": "code",
224
        "colab": {}
225
      },
226
      "source": [
227
        "model, _ = CreateModel(feats, units=[512,512])"
228
      ],
229
      "execution_count": 0,
230
      "outputs": []
231
    },
232
    {
233
      "cell_type": "markdown",
234
      "metadata": {
235
        "id": "-EKBjSapfE4O",
236
        "colab_type": "text"
237
      },
238
      "source": [
239
        "# TrainTestVal\n",
240
        "\n",
241
        "**Input: deepEEG.model, deepEEG.feats**\n",
242
        "\n",
243
        "```python\n",
244
        "batch_size=2\n",
245
        "train_epochs=20\n",
246
        "show_plots=True\n",
247
        "```"
248
      ]
249
    },
250
    {
251
      "cell_type": "code",
252
      "metadata": {
253
        "id": "u6ize7eJfB3J",
254
        "colab_type": "code",
255
        "colab": {}
256
      },
257
      "source": [
258
        "TrainTestVal(model, feats)"
259
      ],
260
      "execution_count": 0,
261
      "outputs": []
262
    }
263
  ]
264
}