Skip to content

Commit ae7dbfe

Browse files
committed
updated assignment 3 instructions, added some code for loading in Polyn et al. (2009) data, started working on assignment 3 template notebook [WIP]
1 parent 2db5e84 commit ae7dbfe

File tree

3 files changed

+58
-99
lines changed

3 files changed

+58
-99
lines changed

content/_toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ parts:
1616
sections:
1717
- file: assignments/Assignment_2:Search_of_Associative_Memory_Model/sam_assignment_template
1818
- file: assignments/Assignment_3:Context_Maintenance_and_Retrieval_Model/README
19+
sections:
20+
- file: assignments/Assignment_3:Context_Maintenance_and_Retrieval_Model/cmr_assignment_template
1921
- file: assignments/Assignment_4:_Laplace_Temporal_Context_Model/README
2022
- file: assignments/Final_Project/README

content/assignments/Assignment_3:Context_Maintenance_and_Retrieval_Model/README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@
44
In this assignment, you will implement the **Context Maintenance and Retrieval (CMR) model** as described in [Polyn, Norman, & Kahana (2009)](https://www.dropbox.com/scl/fi/98pui63j3o62xu96ciwhy/PolyEtal09.pdf?rlkey=42sc17ll573sm83g4q8q9x9nq&dl=1). CMR is a **context-based model of memory search**, extending the **Temporal Context Model (TCM)** to explain how **temporal, semantic, and source context** jointly influence recall. You will fit your implementation to Polyn et al. (2009)'s task-switching free recall data and evaluate how well the model explains the observed recall patterns.
55

66
## Data Format and Preprocessing
7-
The dataset consists of sequences of recalled items from multiple trials of a free recall experiment. Each row represents a participant’s recall sequence from a single list presentation.
8-
9-
- **Numbers (1, 2, ..., N)**: Serial position of recalled items.
10-
- **88**: Denotes errors (recalls of items that were never presented)
11-
- **Example:**
12-
13-
```
14-
6 1 4 7 10 2 8
15-
10 9 6 8 2 1 88
16-
10 7 9 8 1
17-
```
18-
19-
This represents three recall trials. Each row contains the order in which items were recalled for one list.
7+
The dataset comprises sequences of presented and recalled words (concrete nouns) from multiple trials of a free recall experiment. As they were studying each word, participants were either asked to judge the referent's *size* (would it fit in a shoebox?) or *animacy* (does it refer to a living thing?). The dataset also includes information about the similarities in meaning between all of the stimuli (semantic similarities).
8+
9+
Code for downloading and loading the dataset into Python, along with a more detailed description of its contents, may be found in the [template notebook for this assignment](https://github.com/ContextLab/memory-models-course/blob/main/content/assignments/Assignment_3%3AContext_Maintenance_and_Retrieval_Model/cmr_assignment_template.ipynb).
2010

2111
## Model Description
2212

content/assignments/Assignment_3:Context_Maintenance_and_Retrieval_Model/cmr_assignment_template.ipynb

Lines changed: 53 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -32,102 +32,69 @@
3232
]
3333
},
3434
{
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",
8037
"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-
],
9538
"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)"
10149
]
10250
},
10351
{
10452
"cell_type": "code",
105-
"execution_count": 5,
53+
"execution_count": 108,
10654
"id": "b32a7915",
10755
"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": [],
12057
"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()"
12297
]
123-
},
124-
{
125-
"cell_type": "code",
126-
"execution_count": null,
127-
"id": "3e9c2ff7",
128-
"metadata": {},
129-
"outputs": [],
130-
"source": []
13198
}
13299
],
133100
"metadata": {

0 commit comments

Comments
 (0)