|
| 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