Skip to content

Commit

Permalink
Fix/apply max interval to SM-2 (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Nov 8, 2023
1 parent 25cf920 commit 90d5695
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
6 changes: 3 additions & 3 deletions fsrs4anki_optimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# FSRS4Anki v4.10.1 Optimizer\n",
"# FSRS4Anki v4.10.2 Optimizer\n",
"\n",
"[![open in colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-spaced-repetition/fsrs4anki/blob/v4.10.1/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/v4.10.2/fsrs4anki_optimizer.ipynb)\n",
"\n",
"↑ Click the above button to open the optimizer on Google Colab.\n",
"\n",
Expand Down Expand Up @@ -112,7 +112,7 @@
}
],
"source": [
"%pip install -q fsrs_optimizer==4.18.1\n",
"%pip install -q fsrs_optimizer==4.18.2\n",
"# for local development\n",
"# import os\n",
"# import sys\n",
Expand Down
71 changes: 45 additions & 26 deletions fsrs4anki_simulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"id": "jmXx-hS9ZMVj"
},
"source": [
"# FSRS4Anki v4.10.0 Simulator"
"# FSRS4Anki v4.10.2 Simulator"
]
},
{
Expand All @@ -17,7 +17,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/v4.8.3/fsrs4anki_simulator.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/v4.10.2/fsrs4anki_simulator.ipynb)\n",
"\n",
"↑ Click the above button to open the simulator on Google Colab.\n",
"\n",
Expand Down Expand Up @@ -90,10 +90,11 @@
}
],
"source": [
"# %pip install -q fsrs_optimizer==4.18.0\n",
"%pip install -q fsrs_optimizer==4.18.2\n",
"import pandas as pd\n",
"import numpy as np\n",
"import random\n",
"\n",
"# for local development\n",
"# import os\n",
"# import sys\n",
Expand All @@ -111,20 +112,25 @@
"df = pd.read_csv(\"./revlog.csv\")\n",
"df.sort_values(by=[\"card_id\", \"review_time\"], inplace=True, ignore_index=True)\n",
"\n",
"new_card_revlog = df[(df[\"review_state\"] == New) & (df[\"review_rating\"].isin([1, 2, 3, 4]))]\n",
"new_card_revlog = df[\n",
" (df[\"review_state\"] == New) & (df[\"review_rating\"].isin([1, 2, 3, 4]))\n",
"]\n",
"first_rating_prob = np.zeros(4)\n",
"first_rating_prob[new_card_revlog[\"review_rating\"].value_counts().index - 1] = (\n",
" new_card_revlog[\"review_rating\"].value_counts()\n",
" / new_card_revlog[\"review_rating\"].count()\n",
")\n",
"recall_card_revlog = df[(df[\"review_state\"] == Review) & (df[\"review_rating\"].isin([2, 3, 4]))]\n",
"recall_card_revlog = df[\n",
" (df[\"review_state\"] == Review) & (df[\"review_rating\"].isin([2, 3, 4]))\n",
"]\n",
"review_rating_prob = np.zeros(3)\n",
"review_rating_prob[recall_card_revlog[\"review_rating\"].value_counts().index - 2] = (\n",
" recall_card_revlog[\"review_rating\"].value_counts()\n",
" / recall_card_revlog[\"review_rating\"].count()\n",
")\n",
"\n",
"df[\"review_state\"] = df[\"review_state\"].map(lambda x: x if x != New else Learning)\n",
"df[\"review_state\"] = df[\"review_state\"].map(\n",
" lambda x: x if x != New else Learning)\n",
"\n",
"recall_costs = np.zeros(3)\n",
"recall_costs_df = recall_card_revlog.groupby(by=\"review_rating\")[\n",
Expand All @@ -150,7 +156,8 @@
"state_duration[last_state] = duration_sequence[0]\n",
"for i, state in enumerate(state_sequence[1:]):\n",
" state_count[state] = state_count.setdefault(state, 0) + 1\n",
" state_duration[state] = state_duration.setdefault(state, 0) + duration_sequence[i]\n",
" state_duration[state] = state_duration.setdefault(\n",
" state, 0) + duration_sequence[i]\n",
" if state != last_state:\n",
" state_block[state] = state_block.setdefault(state, 0) + 1\n",
" last_state = state\n",
Expand All @@ -159,7 +166,8 @@
"\n",
"if Relearning in state_count and Relearning in state_block:\n",
" forget_cost = round(\n",
" state_duration[Relearning] / state_block[Relearning] / 1000 + recall_cost,\n",
" state_duration[Relearning] /\n",
" state_block[Relearning] / 1000 + recall_cost,\n",
" 1,\n",
" )\n",
"\n",
Expand Down Expand Up @@ -364,23 +372,33 @@
" if factor is None:\n",
" return (graduatingInterval, 2.5) if rating != 4 else (easyInterval, 2.5)\n",
" delay = real_interval - interval\n",
" again_interval = max(\n",
" round(interval * newInterval * intervalModifier + 0.01), minimumInterval\n",
" again_interval = min(\n",
" max(round(interval * newInterval * intervalModifier + 0.01), minimumInterval),\n",
" maximumInterval,\n",
" )\n",
" hard_interval = max(\n",
" round(interval * hardInterval * intervalModifier + 0.01),\n",
" interval + 1,\n",
" minimumInterval,\n",
" hard_interval = min(\n",
" max(\n",
" round(interval * hardInterval * intervalModifier + 0.01),\n",
" interval + 1,\n",
" minimumInterval,\n",
" ),\n",
" maximumInterval,\n",
" )\n",
" good_interval = max(\n",
" round((interval + delay / 2) * factor * intervalModifier + 0.01),\n",
" hard_interval + 1,\n",
" minimumInterval,\n",
" good_interval = min(\n",
" max(\n",
" round((interval + delay / 2) * factor * intervalModifier + 0.01),\n",
" hard_interval + 1,\n",
" minimumInterval,\n",
" ),\n",
" maximumInterval,\n",
" )\n",
" easy_interval = max(\n",
" round(real_interval * factor * intervalModifier * easyBonus + 0.01),\n",
" good_interval + 1,\n",
" minimumInterval,\n",
" easy_interval = min(\n",
" max(\n",
" round(real_interval * factor * intervalModifier * easyBonus + 0.01),\n",
" good_interval + 1,\n",
" minimumInterval,\n",
" ),\n",
" maximumInterval,\n",
" )\n",
" if rating == 1:\n",
" return again_interval, max(factor - 0.2, 1.3)\n",
Expand Down Expand Up @@ -556,15 +574,15 @@
"\n",
" if day >= moving_average_period:\n",
" new_card_per_day_average_per_period[day] = np.true_divide(\n",
" new_card_per_day[day - moving_average_period : day].sum(),\n",
" new_card_per_day[day - moving_average_period: day].sum(),\n",
" moving_average_period,\n",
" )\n",
" review_card_per_day_average_per_period[day] = np.true_divide(\n",
" review_card_per_day[day - moving_average_period : day].sum(),\n",
" review_card_per_day[day - moving_average_period: day].sum(),\n",
" moving_average_period,\n",
" )\n",
" time_per_day_average_per_period[day] = np.true_divide(\n",
" time_per_day[day - moving_average_period : day].sum(),\n",
" time_per_day[day - moving_average_period: day].sum(),\n",
" moving_average_period,\n",
" )\n",
" else:\n",
Expand Down Expand Up @@ -598,7 +616,8 @@
" print(\"learned cards:\", total_learned)\n",
" print(\"time in minutes:\", round(total_time / 60, 1))\n",
" print(\"remembered cards:\", total_remembered)\n",
" print(\"time per remembered card:\", round(total_time / 60 / total_remembered, 2))\n",
" print(\"time per remembered card:\", round(\n",
" total_time / 60 / total_remembered, 2))\n",
" print(\"leeches:\", total_leeches)\n",
"\n",
" save = card[card[\"retrievability\"] > 0].copy()\n",
Expand Down

0 comments on commit 90d5695

Please sign in to comment.