|
41 | 41 | "import pandas as pd\n",
|
42 | 42 | "import numpy as np\n",
|
43 | 43 | "import matplotlib.pyplot as plt\n",
|
44 |
| - "import seaborn as sns" |
| 44 | + "import seaborn as sns\n", |
| 45 | + "\n", |
| 46 | + "import requests\n", |
| 47 | + "import os\n", |
| 48 | + "from tempfile import NamedTemporaryFile" |
45 | 49 | ]
|
46 | 50 | },
|
47 | 51 | {
|
48 | 52 | "cell_type": "markdown",
|
49 |
| - "metadata": { |
50 |
| - "id": "atpXuzOFKDSb" |
51 |
| - }, |
| 53 | + "metadata": {}, |
52 | 54 | "source": [
|
53 |
| - "Basic skeleton for the SAM model" |
| 55 | + "Download dataset and store as `sequence` objects containing the `presented` and `recalled` items for each trial. The sequences are stored in nested dictionaries in the form\n", |
| 56 | + "```\n", |
| 57 | + "dict[list length][presentation rate]\n", |
| 58 | + "```" |
54 | 59 | ]
|
55 | 60 | },
|
56 | 61 | {
|
57 | 62 | "cell_type": "code",
|
58 | 63 | "execution_count": null,
|
59 |
| - "metadata": { |
60 |
| - "id": "PUXuEy_3-q3E" |
61 |
| - }, |
| 64 | + "metadata": {}, |
62 | 65 | "outputs": [],
|
63 | 66 | "source": [
|
64 | 67 | "class item(object):\n",
|
65 |
| - " count = 0\n", |
| 68 | + " idx = 1\n", |
66 | 69 | "\n",
|
67 |
| - " def __init__(self):\n", |
68 |
| - " self.id = count\n", |
69 |
| - " count += 1\n", |
| 70 | + " def __init__(self, val=None):\n", |
| 71 | + " if val is None:\n", |
| 72 | + " self.id = item.idx\n", |
| 73 | + " item.idx += 1\n", |
| 74 | + " else:\n", |
| 75 | + " self.id = val\n", |
70 | 76 | "\n",
|
71 | 77 | "\n",
|
72 | 78 | "class sequence(object):\n",
|
73 |
| - " def __init__(self, items):\n", |
74 |
| - " self.items = items\n", |
| 79 | + " def __init__(self, items):\n", |
| 80 | + " self.items = items\n", |
| 81 | + "\n", |
| 82 | + "\n", |
| 83 | + "def load_recall_data():\n", |
| 84 | + " base_url = \"https://raw.githubusercontent.com/ContextLab/memory-models-course/refs/heads/main/content/assignments/Assignment_2%3ASearch_of_Associative_Memory_Model/Murd62%20data/\"\n", |
| 85 | + " filenames = [\"fr10-2.txt\", \"fr15-2.txt\", \"fr20-1.txt\", \"fr20-2.txt\", \"fr30-1.txt\", \"fr40-1.txt\"]\n", |
| 86 | + "\n", |
| 87 | + " presented = {}\n", |
| 88 | + " recalled = {}\n", |
| 89 | + "\n", |
| 90 | + " for filename in filenames:\n", |
| 91 | + " list_len, pres_rate = map(int, filename.replace(\".txt\", \"\").replace(\"fr\", \"\").split(\"-\"))\n", |
| 92 | + " if list_len not in presented:\n", |
| 93 | + " presented[list_len] = {}\n", |
| 94 | + " recalled[list_len] = {}\n", |
| 95 | + " if pres_rate not in presented[list_len]:\n", |
| 96 | + " presented[list_len][pres_rate] = []\n", |
| 97 | + " recalled[list_len][pres_rate] = []\n", |
75 | 98 | "\n",
|
| 99 | + " # Download the file\n", |
| 100 | + " url = base_url + filename\n", |
| 101 | + " response = requests.get(url)\n", |
| 102 | + " response.raise_for_status()\n", |
| 103 | + " lines = response.text.strip().split(\"\\n\")\n", |
76 | 104 | "\n",
|
| 105 | + " for line in lines:\n", |
| 106 | + " recall_ids = [int(x) for x in line.strip().split() if int(x) != 88]\n", |
| 107 | + " recall_seq = sequence([item(val) for val in recall_ids])\n", |
| 108 | + " presented_seq = sequence([item(val) for val in range(1, list_len + 1)])\n", |
| 109 | + "\n", |
| 110 | + " presented[list_len][pres_rate].append(presented_seq)\n", |
| 111 | + " recalled[list_len][pres_rate].append(recall_seq)\n", |
| 112 | + "\n", |
| 113 | + " return presented, recalled\n", |
| 114 | + "\n", |
| 115 | + "presented, recalled = load_recall_data()" |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + "cell_type": "markdown", |
| 120 | + "metadata": { |
| 121 | + "id": "atpXuzOFKDSb" |
| 122 | + }, |
| 123 | + "source": [ |
| 124 | + "Basic skeleton for the SAM model" |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + "cell_type": "code", |
| 129 | + "execution_count": null, |
| 130 | + "metadata": { |
| 131 | + "id": "PUXuEy_3-q3E" |
| 132 | + }, |
| 133 | + "outputs": [], |
| 134 | + "source": [ |
77 | 135 | "class STS(object):\n",
|
78 | 136 | " def __init__(self, r, q, s_f, s_b, max_items=None, lts=None):\n",
|
79 | 137 | " self.r = r\n",
|
|
142 | 200 | },
|
143 | 201 | "source": [
|
144 | 202 | "Other tasks:\n",
|
145 |
| - " - Fit params to [Murdock (1962) dataset](https://github.com/ContextLab/memory-models-course/tree/main/content/assignments/Assignment_2%3ASearch_of_Associative_Memory_Model/Murd62%20data)\n", |
146 |
| - " - Need to define a \"loss\" function. I suggest computing MSE for one or more behavioral curves, computed for a subset of the Murdock (1962) participants/lists\n", |
| 203 | + " - Fit params to [Murdock (1962) dataset](https://github.com/ContextLab/memory-models-course/tree/main/content/assignments/Assignment_2%3ASearch_of_Associative_Memory_Model/Murd62%20data) that you downloaded with the `load_data` function.\n", |
| 204 | + " - You'll need to define a \"loss\" function. I suggest computing MSE for one or more behavioral curves, computed for a subset of the Murdock (1962) participants/lists\n", |
147 | 205 | " - I suggest using [scipy.optimize.minimize](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) to estimate the model parameters.\n",
|
148 | 206 | " - Create observed/predicted plots for held-out data:\n",
|
149 | 207 | " - p(first recall)\n",
|
|
0 commit comments