Skip to content

Instantly share code, notes, and snippets.

@oflg
Forked from fasiha/README.md
Last active December 18, 2023 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oflg/6c9cc15bbe2172688a0b4bd817b12bd7 to your computer and use it in GitHub Desktop.
Save oflg/6c9cc15bbe2172688a0b4bd817b12bd7 to your computer and use it in GitHub Desktop.
How Anki calculates intervals

Reading _nextRevIvl and its subfunction _constrainedIvl plus _rescheduleLapse will illuminate how Anki calculates the due date of a flashcard, based on whether you answer

  • again
  • hard
  • good
  • easy

This is more of a self-note, so I assume you’ve read the Anki manual top-to-bottom a couple of times.

Let factor be the flashcard’s factor, by default be the Starting Ease, default startingease = 2.5, which is Anki’s estimate for how well you’ve memorized this flashcard. The bigger the number, the better you understand it. It’s minimum is 1.3 and it gets incremented by 0.15 to 0.2 points every review, as we will show below. The manual also calls this ease. Recall that factor is Anki’s guess of the strengh of the memory in your mind, and it controls the exponential growth of intervals for good and easy reivews.

Here’s how to calculate the new factor:

  • factor = max(1.3, last_factor - 0.2) when you fail a review (reference)
  • factor = max(1.3, last_factor - 0.15) for a hard review.
  • factor = max(1.3, last_factor) for a good review. No change in factor.
  • factor = max(1.3, last_factor + 0.15) for an easy review (reference).

Let the interval be the flashcard’s interval, by default be the New Interval, default newinterval = 0. Let intervalmodifier be the Interval Modifier, default intervalmodifier = 1, a number nominally around 1.0 but that a user can set higher or lower. Anki multiplies the interval by this number, letting the user ask for more or less time between reviews uniformly, across all cards. Let hardinterval be the Hard Interval, which applies for hard reviews, default hardinterval = 1.2. Let easybonus be the Easy Bonus, default easybonus = 1.3, which applies for easy reviews. Let delay be the days between the due date and the date you actually reviewed, and delay>=0. This can be important because if you successfully answer a flashcard a long time after it was due for study, that means you probably know it really well.

Here’s how to calculate the new interval:

  • again_interval = newinterval * last_interval is the new interval for failed reviews. It can have a minimum.
  • hard_interval = max(last_interval + 1, (last_interval + delay//4) * hardinterval * intervalmodifier) is the new interval for hard reviews.
  • good_interval = max(hard_interval + 1, (last_interval + delay//2) * last_factor * intervalmodifier) is the new interval for good reviews.
  • easy_interval = max(good_interval + 1, (last_interval + delay) * last_factor * easybonus * intervalmodifier) is the new interval for easy reviews.

The new interval can be limited to Maximum Interval, default maximuminterval=36500 day.

Finally, new due date is the day you actually review + new interval.

@Aaaaidan
Copy link

"Let factor be the flashcard’s factor, by default be the Starting Ease, default startingease = 2.5, which is Anki’s estimate for how well you’ve memorized this flashcard. The bigger the number, the better you understand it. It’s maximum is 1.3"

How can the maximum be 1.3 when the default starting value is 2.5?

@oflg
Copy link
Author

oflg commented Dec 17, 2023

Sorry, I wrote it wrong, it was affected by the following max(1.3, ...) .

A minimum value of 1.3 is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment