Skip to content

Commit

Permalink
Fix/padding for missing difficulty (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Oct 22, 2022
1 parent 69d0d3a commit 8866623
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions fsrs4anki_optimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# FSRS4Anki v3.7.2 Optimizer"
"# FSRS4Anki v3.7.3 Optimizer"
]
},
{
Expand All @@ -13,7 +13,7 @@
"id": "lurCmW0Jqz3s"
},
"source": [
"[![open in colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-spaced-repetition/fsrs4anki/blob/v3.7.2/fsrs4anki_optimizer.ipynb)\n",
"[![open in colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-spaced-repetition/fsrs4anki/blob/v3.7.3/fsrs4anki_optimizer.ipynb)\n",
"\n",
"↑ Click the above button to open the optimizer on Google Colab.\n",
"\n",
Expand Down Expand Up @@ -168,7 +168,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "229adb56518642a5ab9cfad3566cedd6",
"model_id": "938a105559a74749bac5db152a152b25",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -189,7 +189,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1574fdfb2eb24b39a8efd890fb5d25b6",
"model_id": "8d2ad4198a0f4f509d72ebfd2edfefe4",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -210,7 +210,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "838442ed30ca4844b0706b6f0b15ce89",
"model_id": "d3281531f77948b3aa6b1480c08ff6cd",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -231,7 +231,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bb861f0577c74f2b93d3e58d9351f23e",
"model_id": "c5c1302dda1446e5a4db4b0fe5f30618",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -512,7 +512,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a14a9933f83c4a7f9d27f5d10abb339a",
"model_id": "ee1f00cd92b34d2f934c46332ff0dd11",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -533,7 +533,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8ca726bacf7c4676aa69091ef5897180",
"model_id": "fc5d8600a3f24df6a2067629ebaf4ba1",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -554,7 +554,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "185401a102724eccb703e58212e0ba9a",
"model_id": "8771aa22a0bd4f2a97b247993e65cf9e",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -871,7 +871,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3bf7133e87e94ac8a101ad1899667adf",
"model_id": "06c3ad750cb04f8f9e34a40da02fb032",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -923,7 +923,11 @@
"print(\"prediction.tsv saved.\")\n",
"prediction['difficulty'] = prediction['difficulty'].map(lambda x: int(round(x)))\n",
"difficulty_distribution = prediction.groupby(by=['difficulty'])['count'].sum() / prediction['count'].sum()\n",
"print(difficulty_distribution)"
"print(difficulty_distribution)\n",
"difficulty_distribution_padding = np.zeros(10)\n",
"for i in range(10):\n",
" if i+1 in difficulty_distribution.index:\n",
" difficulty_distribution_padding[i] = difficulty_distribution.loc[i+1]"
]
},
{
Expand All @@ -948,7 +952,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "57030c69be8240d984c78703d1ce3449",
"model_id": "6c1c0441e5454ac0a3a9407554c89e5d",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -1038,14 +1042,14 @@
"df.to_csv(\"./expected_repetitions.csv\", index=False)\n",
"print(\"expected_repetitions.csv saved.\")\n",
"\n",
"optimal_retention_list = []\n",
"optimal_retention_list = np.zeros(10)\n",
"for d in range(1, d_range+1):\n",
" retention = df[df[\"difficulty\"] == d][\"retention\"]\n",
" repetitions = df[df[\"difficulty\"] == d][\"repetitions\"]\n",
" optimal_retention = retention.iat[repetitions.argmin()]\n",
" optimal_retention_list.append(optimal_retention)\n",
" optimal_retention_list[d-1] = optimal_retention\n",
" plt.plot(retention, repetitions, label=f\"d={d}, r={optimal_retention}\")\n",
"print(f\"\\n-----suggested retention: {np.inner(np.array(difficulty_distribution), np.array(optimal_retention_list)):.2f}-----\")\n",
"print(f\"\\n-----suggested retention: {np.inner(difficulty_distribution_padding, optimal_retention_list):.2f}-----\")\n",
"plt.ylabel(\"expected repetitions\")\n",
"plt.xlabel(\"retention\")\n",
"plt.legend()\n",
Expand Down

0 comments on commit 8866623

Please sign in to comment.