|
32 | 32 | ]
|
33 | 33 | },
|
34 | 34 | {
|
35 |
| - "cell_type": "code", |
36 |
| - "execution_count": null, |
37 |
| - "id": "3b750171", |
38 |
| - "metadata": {}, |
39 |
| - "outputs": [], |
40 |
| - "source": [ |
41 |
| - "def load_recall_data():\n", |
42 |
| - " 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", |
43 |
| - " filenames = [\"stimuli.mat\", \"behavior.mat\"]\n", |
44 |
| - "\n", |
45 |
| - " presented = {}\n", |
46 |
| - " recalled = {}\n", |
47 |
| - "\n", |
48 |
| - " for filename in filenames:\n", |
49 |
| - " list_len, pres_rate = map(int, filename.replace(\".txt\", \"\").replace(\"fr\", \"\").split(\"-\"))\n", |
50 |
| - " if list_len not in presented:\n", |
51 |
| - " presented[list_len] = {}\n", |
52 |
| - " recalled[list_len] = {}\n", |
53 |
| - " if pres_rate not in presented[list_len]:\n", |
54 |
| - " presented[list_len][pres_rate] = []\n", |
55 |
| - " recalled[list_len][pres_rate] = []\n", |
56 |
| - "\n", |
57 |
| - " # Download the file\n", |
58 |
| - " url = base_url + filename\n", |
59 |
| - " response = requests.get(url)\n", |
60 |
| - " response.raise_for_status()\n", |
61 |
| - " lines = response.text.strip().split(\"\\n\")\n", |
62 |
| - "\n", |
63 |
| - " for line in lines:\n", |
64 |
| - " recall_ids = [int(x) for x in line.strip().split() if int(x) != 88]\n", |
65 |
| - " recall_seq = sequence([item(val) for val in recall_ids])\n", |
66 |
| - " presented_seq = sequence([item(val) for val in range(1, list_len + 1)])\n", |
67 |
| - "\n", |
68 |
| - " presented[list_len][pres_rate].append(presented_seq)\n", |
69 |
| - " recalled[list_len][pres_rate].append(recall_seq)\n", |
70 |
| - "\n", |
71 |
| - " return presented, recalled\n", |
72 |
| - "\n", |
73 |
| - "presented, recalled = load_recall_data()" |
74 |
| - ] |
75 |
| - }, |
76 |
| - { |
77 |
| - "cell_type": "code", |
78 |
| - "execution_count": 6, |
79 |
| - "id": "cd3cf0a5", |
| 35 | + "cell_type": "markdown", |
| 36 | + "id": "1539bcff", |
80 | 37 | "metadata": {},
|
81 |
| - "outputs": [ |
82 |
| - { |
83 |
| - "ename": "HTTPError", |
84 |
| - "evalue": "404 Client Error: Not Found for url: https://raw.githubusercontent.com/ContextLab/memory-models-course/refs/heads/main/content/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/PolyEtal09%20data/stimuli.mat", |
85 |
| - "output_type": "error", |
86 |
| - "traceback": [ |
87 |
| - "\u001b[31m---------------------------------------------------------------------------\u001b[39m", |
88 |
| - "\u001b[31mHTTPError\u001b[39m Traceback (most recent call last)", |
89 |
| - "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 1\u001b[39m base_url = \u001b[33m\"\u001b[39m\u001b[33mhttps://raw.githubusercontent.com/ContextLab/memory-models-course/refs/heads/main/content/assignments/Assignment_3\u001b[39m\u001b[33m%\u001b[39m\u001b[33m3AContext_Maintenance_and_Retrieval_Model/PolyEtal09\u001b[39m\u001b[38;5;132;01m%20d\u001b[39;00m\u001b[33mata/\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 2\u001b[39m filenames = [\u001b[33m\"\u001b[39m\u001b[33mstimuli.mat\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mbehavior.mat\u001b[39m\u001b[33m\"\u001b[39m]\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m stimuli = requests.get(base_url + \u001b[33m\"\u001b[39m\u001b[33mstimuli.mat\u001b[39m\u001b[33m\"\u001b[39m).raise_for_status()\n\u001b[32m 5\u001b[39m behavior = requests.get(base_url + \u001b[33m\"\u001b[39m\u001b[33mbehavior.mat\u001b[39m\u001b[33m\"\u001b[39m).raise_for_status()\n", |
90 |
| - "\u001b[36mFile \u001b[39m\u001b[32m~/memory-models-course/memory-course/lib/python3.11/site-packages/requests/models.py:1024\u001b[39m, in \u001b[36mResponse.raise_for_status\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 1019\u001b[39m http_error_msg = (\n\u001b[32m 1020\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m.status_code\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m Server Error: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mreason\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m for url: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m.url\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 1021\u001b[39m )\n\u001b[32m 1023\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[32m-> \u001b[39m\u001b[32m1024\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response=\u001b[38;5;28mself\u001b[39m)\n", |
91 |
| - "\u001b[31mHTTPError\u001b[39m: 404 Client Error: Not Found for url: https://raw.githubusercontent.com/ContextLab/memory-models-course/refs/heads/main/content/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/PolyEtal09%20data/stimuli.mat" |
92 |
| - ] |
93 |
| - } |
94 |
| - ], |
95 | 38 | "source": [
|
96 |
| - "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", |
97 |
| - "filenames = [\"stimuli.mat\", \"behavior.mat\"]\n", |
98 |
| - "\n", |
99 |
| - "stimuli = requests.get(base_url + \"stimuli.mat\").raise_for_status()\n", |
100 |
| - "behavior = requests.get(base_url + \"behavior.mat\").raise_for_status()" |
| 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)" |
101 | 49 | ]
|
102 | 50 | },
|
103 | 51 | {
|
104 | 52 | "cell_type": "code",
|
105 |
| - "execution_count": 5, |
| 53 | + "execution_count": 108, |
106 | 54 | "id": "b32a7915",
|
107 | 55 | "metadata": {},
|
108 |
| - "outputs": [ |
109 |
| - { |
110 |
| - "data": { |
111 |
| - "text/plain": [ |
112 |
| - "<Response [404]>" |
113 |
| - ] |
114 |
| - }, |
115 |
| - "execution_count": 5, |
116 |
| - "metadata": {}, |
117 |
| - "output_type": "execute_result" |
118 |
| - } |
119 |
| - ], |
| 56 | + "outputs": [], |
120 | 57 | "source": [
|
121 |
| - "stimuli" |
| 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()" |
122 | 97 | ]
|
123 |
| - }, |
124 |
| - { |
125 |
| - "cell_type": "code", |
126 |
| - "execution_count": null, |
127 |
| - "id": "3e9c2ff7", |
128 |
| - "metadata": {}, |
129 |
| - "outputs": [], |
130 |
| - "source": [] |
131 | 98 | }
|
132 | 99 | ],
|
133 | 100 | "metadata": {
|
|
0 commit comments