Skip to content

Commit 63737a0

Browse files
committed
added colab link
1 parent ae7dbfe commit 63737a0

File tree

1 file changed

+151
-119
lines changed

1 file changed

+151
-119
lines changed
Lines changed: 151 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,153 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"id": "1a163c99",
6-
"metadata": {},
7-
"source": [
8-
"# Submission Template\n",
9-
"\n",
10-
"This notebook provides a suggested starter template for completing the [CMR model assignment](https://contextlab.github.io/memory-models-course/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/README.html).\n",
11-
"\n",
12-
"You should submit your assignment by uploading your completed notebook to [Canvas](https://canvas.dartmouth.edu/courses/71051/assignments/517355). Please ensure that your notebook runs without errors in [Google Colaboratory](https://colab.research.google.com/)."
13-
]
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "view-in-github",
7+
"colab_type": "text"
8+
},
9+
"source": [
10+
"<a href=\"https://colab.research.google.com/github/ContextLab/memory-models-course/blob/main/content/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/cmr_assignment_template.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "1a163c99",
16+
"metadata": {
17+
"id": "1a163c99"
18+
},
19+
"source": [
20+
"# Submission Template\n",
21+
"\n",
22+
"This notebook provides a suggested starter template for completing the [CMR model assignment](https://contextlab.github.io/memory-models-course/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/README.html).\n",
23+
"\n",
24+
"You should submit your assignment by uploading your completed notebook to [Canvas](https://canvas.dartmouth.edu/courses/71051/assignments/517355). Please ensure that your notebook runs without errors in [Google Colaboratory](https://colab.research.google.com/)."
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 1,
30+
"id": "137eb31f",
31+
"metadata": {
32+
"id": "137eb31f"
33+
},
34+
"outputs": [],
35+
"source": [
36+
"import pandas as pd\n",
37+
"import numpy as np\n",
38+
"import matplotlib.pyplot as plt\n",
39+
"import seaborn as sns\n",
40+
"\n",
41+
"import requests\n",
42+
"import os\n",
43+
"\n",
44+
"from scipy.io import loadmat\n",
45+
"from tempfile import NamedTemporaryFile"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"id": "1539bcff",
51+
"metadata": {
52+
"id": "1539bcff"
53+
},
54+
"source": [
55+
"Download the stimuli and behavioral data, returned as a dictionary with the following fields:\n",
56+
" - 'words': a list of 1297 strings (one per word in the stimulus pool)\n",
57+
" - 'sem_mat': a 1297 x 1297 NumPy array of semantic similarities (range: -1 to 1) between every pair of words in the stimulus pool\n",
58+
" - 'presented_items': a number-of-trials by list-length array of items for each presented list (represented using 0-indexed indices in the word pool)\n",
59+
" - 'recalled_items': a number-of-trials by max-number-of-recalled-items array of recalled items from each list (represented using 0-indexed indices in the word pool). -1s correspond to extra-list intrusions. Trials are right-padded with nans as needed.\n",
60+
" - 'task': a number-of-trials by list-length array of task labels for each presented item (0: size task; 1: animacy task)\n",
61+
" - 'session': session labels for each trial (a NumPy array of length number-of-trials)\n",
62+
" - 'subject': subject labels for each trial (a NumPy array of length number-of-trials)\n",
63+
" - 'list_type': list type labels for each trial (a NumPy array of length number-of-trials; 0: all items studied using the size task; 1: all items studied using the animacy task; 2: task-shift list)\n",
64+
" - 'list_length': a scalar value containing the list length (an integer)"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": 2,
70+
"id": "b32a7915",
71+
"metadata": {
72+
"id": "b32a7915"
73+
},
74+
"outputs": [],
75+
"source": [
76+
"def load_data():\n",
77+
" # Download the files\n",
78+
" base_url = \"https://raw.githubusercontent.com/ContextLab/memory-models-course/refs/heads/main/content/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/PolyEtal09%20data/\"\n",
79+
"\n",
80+
" # download the stimuli\n",
81+
" response = requests.get(base_url + \"stimuli.mat\")\n",
82+
" response.raise_for_status()\n",
83+
" with NamedTemporaryFile(delete=False) as temp_file:\n",
84+
" temp_file.write(response.content)\n",
85+
" stimuli_data = loadmat(temp_file.name)\n",
86+
" words = [str(x[0][0]) for x in stimuli_data['tfr_wp']]\n",
87+
" sem_mat = stimuli_data['sem_mat']\n",
88+
" os.remove(temp_file.name)\n",
89+
"\n",
90+
" # download the behavioral data\n",
91+
" response = requests.get(base_url + \"behavior.mat\")\n",
92+
" response.raise_for_status()\n",
93+
" with NamedTemporaryFile(delete=False) as temp_file:\n",
94+
" temp_file.write(response.content)\n",
95+
" behavioral_data = loadmat(temp_file.name)\n",
96+
" presented_items = behavioral_data['data'][0][0][0][0][0]['pres_itemnos']\n",
97+
" recalled_items = behavioral_data['data'][0][0][0][0][0]['rec_itemnos']\n",
98+
" task = behavioral_data['data'][0][0][0][0][0]['pres_task']\n",
99+
" session = behavioral_data['data'][0][0][0][0][0]['session'].flatten()\n",
100+
" subject = behavioral_data['data'][0][0][0][0][0]['subject'].flatten()\n",
101+
" list_type = behavioral_data['data'][0][0][0][0][0]['listType'].flatten()\n",
102+
" os.remove(temp_file.name)\n",
103+
"\n",
104+
" return {'words': words,\n",
105+
" 'sem_mat': sem_mat,\n",
106+
" 'presented_items': presented_items - 1,\n",
107+
" 'recalled_items': recalled_items - 1,\n",
108+
" 'task': task,\n",
109+
" 'session': session,\n",
110+
" 'subject': subject,\n",
111+
" 'list_type': list_type,\n",
112+
" 'list_length': int(behavioral_data['data'][0][0][0][0][0]['listLength'].flatten()[0])}\n",
113+
"\n",
114+
"data = load_data()"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"source": [],
120+
"metadata": {
121+
"id": "IjVqOOsZEM4q"
122+
},
123+
"id": "IjVqOOsZEM4q",
124+
"execution_count": null,
125+
"outputs": []
126+
}
127+
],
128+
"metadata": {
129+
"kernelspec": {
130+
"display_name": "memory-course",
131+
"language": "python",
132+
"name": "memory-course"
133+
},
134+
"language_info": {
135+
"codemirror_mode": {
136+
"name": "ipython",
137+
"version": 3
138+
},
139+
"file_extension": ".py",
140+
"mimetype": "text/x-python",
141+
"name": "python",
142+
"nbconvert_exporter": "python",
143+
"pygments_lexer": "ipython3",
144+
"version": "3.11.0"
145+
},
146+
"colab": {
147+
"provenance": [],
148+
"include_colab_link": true
149+
}
14150
},
15-
{
16-
"cell_type": "code",
17-
"execution_count": 3,
18-
"id": "137eb31f",
19-
"metadata": {},
20-
"outputs": [],
21-
"source": [
22-
"import pandas as pd\n",
23-
"import numpy as np\n",
24-
"import matplotlib.pyplot as plt\n",
25-
"import seaborn as sns\n",
26-
"\n",
27-
"import requests\n",
28-
"import os\n",
29-
"\n",
30-
"from scipy.io import loadmat\n",
31-
"from tempfile import NamedTemporaryFile"
32-
]
33-
},
34-
{
35-
"cell_type": "markdown",
36-
"id": "1539bcff",
37-
"metadata": {},
38-
"source": [
39-
"Download the stimuli and behavioral data, returned as a dictionary with the following fields:\n",
40-
" - 'words': a list of 1297 strings (one per word in the stimulus pool)\n",
41-
" - 'sem_mat': a 1297 x 1297 NumPy array of semantic similarities (range: -1 to 1) between every pair of words in the stimulus pool\n",
42-
" - 'presented_items': a number-of-trials by list-length array of items for each presented list (represented using 0-indexed indices in the word pool)\n",
43-
" - 'recalled_items': a number-of-trials by max-number-of-recalled-items array of recalled items from each list (represented using 0-indexed indices in the word pool). -1s correspond to extra-list intrusions. Trials are right-padded with nans as needed.\n",
44-
" - 'task': a number-of-trials by list-length array of task labels for each presented item (0: size task; 1: animacy task)\n",
45-
" - 'session': session labels for each trial (a NumPy array of length number-of-trials)\n",
46-
" - 'subject': subject labels for each trial (a NumPy array of length number-of-trials)\n",
47-
" - 'list_type': list type labels for each trial (a NumPy array of length number-of-trials; 0: all items studied using the size task; 1: all items studied using the animacy task; 2: task-shift list)\n",
48-
" - 'list_length': a scalar value containing the list length (an integer)"
49-
]
50-
},
51-
{
52-
"cell_type": "code",
53-
"execution_count": 108,
54-
"id": "b32a7915",
55-
"metadata": {},
56-
"outputs": [],
57-
"source": [
58-
"def load_data():\n",
59-
" # Download the files\n",
60-
" base_url = \"https://raw.githubusercontent.com/ContextLab/memory-models-course/refs/heads/main/content/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/PolyEtal09%20data/\"\n",
61-
"\n",
62-
" # download the stimuli\n",
63-
" response = requests.get(base_url + \"stimuli.mat\")\n",
64-
" response.raise_for_status()\n",
65-
" with NamedTemporaryFile(delete=False) as temp_file:\n",
66-
" temp_file.write(response.content)\n",
67-
" stimuli_data = loadmat(temp_file.name)\n",
68-
" words = [str(x[0][0]) for x in stimuli_data['tfr_wp']]\n",
69-
" sem_mat = stimuli_data['sem_mat']\n",
70-
" os.remove(temp_file.name)\n",
71-
"\n",
72-
" # download the behavioral data\n",
73-
" response = requests.get(base_url + \"behavior.mat\")\n",
74-
" response.raise_for_status()\n",
75-
" with NamedTemporaryFile(delete=False) as temp_file:\n",
76-
" temp_file.write(response.content)\n",
77-
" behavioral_data = loadmat(temp_file.name)\n",
78-
" presented_items = behavioral_data['data'][0][0][0][0][0]['pres_itemnos']\n",
79-
" recalled_items = behavioral_data['data'][0][0][0][0][0]['rec_itemnos']\n",
80-
" task = behavioral_data['data'][0][0][0][0][0]['pres_task']\n",
81-
" session = behavioral_data['data'][0][0][0][0][0]['session'].flatten()\n",
82-
" subject = behavioral_data['data'][0][0][0][0][0]['subject'].flatten()\n",
83-
" list_type = behavioral_data['data'][0][0][0][0][0]['listType'].flatten() \n",
84-
" os.remove(temp_file.name)\n",
85-
"\n",
86-
" return {'words': words,\n",
87-
" 'sem_mat': sem_mat,\n",
88-
" 'presented_items': presented_items - 1,\n",
89-
" 'recalled_items': recalled_items - 1,\n",
90-
" 'task': task,\n",
91-
" 'session': session,\n",
92-
" 'subject': subject,\n",
93-
" 'list_type': list_type,\n",
94-
" 'list_length': int(behavioral_data['data'][0][0][0][0][0]['listLength'].flatten()[0])}\n",
95-
"\n",
96-
"data = load_data()"
97-
]
98-
}
99-
],
100-
"metadata": {
101-
"kernelspec": {
102-
"display_name": "memory-course",
103-
"language": "python",
104-
"name": "memory-course"
105-
},
106-
"language_info": {
107-
"codemirror_mode": {
108-
"name": "ipython",
109-
"version": 3
110-
},
111-
"file_extension": ".py",
112-
"mimetype": "text/x-python",
113-
"name": "python",
114-
"nbconvert_exporter": "python",
115-
"pygments_lexer": "ipython3",
116-
"version": "3.11.0"
117-
}
118-
},
119-
"nbformat": 4,
120-
"nbformat_minor": 5
121-
}
151+
"nbformat": 4,
152+
"nbformat_minor": 5
153+
}

0 commit comments

Comments
 (0)