Skip to content

Commit 2db5e84

Browse files
committed
updated SAM assignment, working on CMR assignment
1 parent 95b6239 commit 2db5e84

File tree

7 files changed

+265
-9
lines changed

7 files changed

+265
-9
lines changed

content/assignments/Assignment_2:Search_of_Associative_Memory_Model/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ Alternatively, if an item $i$ is sampled through its associations with both item
8787
p(\text{recall item }i | j, context) = 1 - \exp{\\( -W_e S(i, j) - W_c S(i, context)\\)}.
8888
$$
8989

90-
To decide whether a given recall (of item $i$) occurs, draw a random number $\theta$ uniformly from the interval $[0, 1]$. If $\theta < p(\text{recall item }i)$ then the item is recalled (and two "counter" parameters, $m_1$ and $m_2$, are both reset to 0). Otherwise the recall failure procedure is called next.
90+
To decide whether a given recall (of item $i$) occurs, draw a random number $\theta$ uniformly from the interval $[0, 1]$. If $\theta < p(\text{recall item }i)$ then:
91+
- the two "counter" parameters, $m_1$ and $m_2$, are both reset to 0
92+
- $S(i, context)$ is incremented by $a_\text{forward}$
93+
- item $i$ is recalled
94+
95+
Otherwise the recall failure procedure is called next.
9196

9297
#### Recall failures
9398

content/assignments/Assignment_2:Search_of_Associative_Memory_Model/sam_assignment_template.ipynb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": null,
35+
"execution_count": 1,
3636
"metadata": {
3737
"id": "rh59uGAx-N5O"
3838
},
@@ -60,7 +60,7 @@
6060
},
6161
{
6262
"cell_type": "code",
63-
"execution_count": null,
63+
"execution_count": 3,
6464
"metadata": {},
6565
"outputs": [],
6666
"source": [
@@ -126,7 +126,7 @@
126126
},
127127
{
128128
"cell_type": "code",
129-
"execution_count": null,
129+
"execution_count": 5,
130130
"metadata": {
131131
"id": "PUXuEy_3-q3E"
132132
},
@@ -190,7 +190,8 @@
190190
" # (if previous_recall is the only item left, return None)\n",
191191
" # - recall (given cue strength):\n",
192192
" # - if successful, reset m1_count and m2_count, set previous_recall to item, return sampled item\n",
193-
" # - otherwise increment m1_count or m2_count. if either exceed M_1/M2, return None"
193+
" # - otherwise increment m1_count or m2_count. if either exceed M_1/M2, return None\n",
194+
" pass"
194195
]
195196
},
196197
{
@@ -216,11 +217,21 @@
216217
"provenance": []
217218
},
218219
"kernelspec": {
219-
"display_name": "Python 3",
220-
"name": "python3"
220+
"display_name": "memory-course",
221+
"language": "python",
222+
"name": "memory-course"
221223
},
222224
"language_info": {
223-
"name": "python"
225+
"codemirror_mode": {
226+
"name": "ipython",
227+
"version": 3
228+
},
229+
"file_extension": ".py",
230+
"mimetype": "text/x-python",
231+
"name": "python",
232+
"nbconvert_exporter": "python",
233+
"pygments_lexer": "ipython3",
234+
"version": "3.11.0"
224235
}
225236
},
226237
"nbformat": 4,
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
This archive contains a MATLAB-based data structure containing the behavioral data
2+
from the experiment described in the article:
3+
4+
A Context Maintenance and Retrieval Model of Organizational Processes in Free Recall
5+
6+
Sean M. Polyn, Kenneth A. Norman, and Michael J. Kahana
7+
8+
Psychological Review, Vol. 116 (1), 129-156.
9+
10+
Refer to this manuscript for the methods of the experiment, and description of the
11+
analyses that we carried out on these data.
12+
13+
%%%%%%%%%%%%%%%%%%%
14+
15+
This particular file written by Sean Polyn
16+
17+
on September 25th, 2013
18+
19+
Send word if you find anything weird or out of sorts with the data, or the explanation of the organization of the data!
20+
21+
If you are interested in the Context Maintenance and Retrieval model of human memory, go to this webpage:
22+
http://memory.psy.vanderbilt.edu/groups/vcml/wiki/618f3/CMR_Documentation.html
23+
24+
Behavioral Toolbox (Release 1) analysis code available from:
25+
http://memory.psych.upenn.edu/behavioral_toolbox
26+
27+
%%%%%%%%%%%%%%%%%%%
28+
29+
A quick tour of the data structure.
30+
31+
%%%%%%%%%%%%%%%%%%%
32+
33+
If you load the file PolyEtal09_data.mat in MATLAB, you will find a structure with three fields:
34+
35+
data.full % Data from all of the trials from the experiment, from all conditions, including practice trials
36+
data.co % Just the control trials, in which all items were studied using the same encoding task
37+
data.sh % Just the task-shift trials, in which participants shifted back and forth between the two encoding tasks
38+
39+
The organization of the sub-fields:
40+
41+
There are a number of sub-fields on the data structure. Each row corresponds to a particular trial. If there is more than one column, then there are two possible organizations, refer below to see which one applies. (1) Yoked to the presentation order, each column corresponds to a study event. (2) Yoked to the recall order, each column corresponds to a recall event.
42+
43+
The most critical sub-fields:
44+
45+
data.subject % Each row has a numerical index, a unique subject identifier. There are 45 unique subject identifiers. The careful
46+
% observer will note that index 19 is skipped, this participant did not complete the study.
47+
data.listType % 0 = all items studied using the SIZE task, 1 = all items studied using ANIMACY task, 2 = task-shift list
48+
data.recalls % A numerical identifier for each response made by the participant during the free recall period. Integers 1-24
49+
% correspond to the serial position of the recalled item. Yoked to the recall order. -1 corresponds to an intrusion.
50+
% -2 corresponds to a repetition.
51+
data.pres_task % Which task was associated with each studied item, columns yoked to presentation events.
52+
% Task 0 is SIZE
53+
% Task 1 is ANIMACY
54+
data.listLength % There were 24 items on each study list
55+
56+
The other sub-fields:
57+
58+
data.session % A session label for each trial, either 1 or 2
59+
data.pres_itemnos % Each studied item has an index for the wordpool. Yoked to presentation order.
60+
data.react_time % Yoked to the study period. Time to make the task response in milliseconds.
61+
data.intrusions % -1 for extra-experimental intrusion, positive numbers correspond to how many lists back a prior-list intrusion
62+
% came from.
63+
data.times % For each recall response, how many milliseconds after the onset of the recall period was this response made.
64+
65+
Convenience fields (technically these are redundant with information in the other fields):
66+
67+
data.task % The task label of each recalled item (can be constructed with pres_task and recalls)
68+
data.rec_itemnos % The wordpool index for each recalled item (can be constructed with pres_itemnos and recalls)
69+
data.pres_subrec % Yoked to presentation order. 1 if the item will be recalled.
70+
data.pres_trainno % Yoked to presentation order. Labeling each item as to whether it is in the first train, second train, etc.
71+
data.pres_trainlen % Yoked to presentation order. How long is the train that the item resides in.
72+
data.pres_sertrain % Yoked to presentation order. Serial position of the item within a given train.
73+
data.train % Yoked to recall order, as above.
74+
data.trainlen % Yoked to recall order, as above.
75+
data.sertrain % Yoked to recall order, as above.
76+
77+
%%%%%%%%%%%%%%%%%%%
78+
79+
Other files that are included.
80+
81+
%%%%%%%%%%%%%%%%%%%
82+
83+
tfr_wp % This is the wordpool for the experiment. The index values in pres_itemnos and rec_itemnos can be used to
84+
% figure out which words are presented on each trial.
85+
86+
sem_mat % These are the LSA values used for the semantic analyses described

content/assignments/Assignment_3:Context_Maintenance_and_Retrieval_Model/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Assignment 3: Context Maintenance and Retrieval (CMR)
22

33
## Overview
4-
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 [Murdock (1962)](https://www.dropbox.com/scl/fi/k7jc1b6uua4m915maglpl/Murd62.pdf?rlkey=i5nc7lzb2pw8dxc6xc72r5r5i&dl=1) free recall data and evaluate how well the model explains the observed recall patterns.
4+
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
77
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.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
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+
]
14+
},
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": "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",
80+
"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+
"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()"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 5,
106+
"id": "b32a7915",
107+
"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+
],
120+
"source": [
121+
"stimuli"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": null,
127+
"id": "3e9c2ff7",
128+
"metadata": {},
129+
"outputs": [],
130+
"source": []
131+
}
132+
],
133+
"metadata": {
134+
"kernelspec": {
135+
"display_name": "memory-course",
136+
"language": "python",
137+
"name": "memory-course"
138+
},
139+
"language_info": {
140+
"codemirror_mode": {
141+
"name": "ipython",
142+
"version": 3
143+
},
144+
"file_extension": ".py",
145+
"mimetype": "text/x-python",
146+
"name": "python",
147+
"nbconvert_exporter": "python",
148+
"pygments_lexer": "ipython3",
149+
"version": "3.11.0"
150+
}
151+
},
152+
"nbformat": 4,
153+
"nbformat_minor": 5
154+
}

0 commit comments

Comments
 (0)