Skip to content

Instantly share code, notes, and snippets.

@fasiha
Last active April 7, 2023 14:15
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fasiha/31ce46c36371ff57fdbc1254af424174 to your computer and use it in GitHub Desktop.
Save fasiha/31ce46c36371ff57fdbc1254af424174 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 (the “interval”) of a flashcard, based on whether you answer

  • 1 (fail)
  • 2 (pass but hard)
  • 3 (pass)
  • 4 (pass and 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 d >= 0, “delay”, be the days between the due date and the date you actually reviewed. 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.

Let f, “factor” be the flashcard’s factor, 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 1300 and it gets incremented by 150 to 200 “points” every review, as we will show below. The manual also calls this “ease”.

A few user-configured parameters. Let m be the “interval modifier”, 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 m4 be another user-specified interval modifier, by default 1.3, which applies for “easy” reviews (hence the “4” in the name). And let m0 be the user-specified “new interval”, i.e., a small number closer to 0 than 1 that’s used when you fail a card. By default m0 = 0.

Finally, let i be the most-recent interval.

Here’s how to calculate the new interval:

  • i1 = m0 * i is the new interval for failed reviews. It can have a minimum.
  • i2 = max(i + 1, (i + d/4) * 1.2 * m) is the new interval for hard reviews.
  • i3 = max(i2 + 1, (i + d/2) * (f / 1000) * m) is the new interval for ok reviews.
  • i4 = max(i3 + 1, (i + d) * (f / 1000) * m * m4) is the new interval for easy reviews.

And here’s another very important piece: how to calculate the new factor f. Recall that this is Anki’s guess of the strengh of the memory in your mind, and it controls the exponential growth of intervals for ok (#3) and easy (#4) reivews.

  • f' = max(1300, f - 200) when you fail a review (#1, reference)
  • f' = max(1300, f - 150) for a hard review (#2).
  • f' = f for an ok review (#3). No change in factor.
  • f' = max(1300, f + 150) for an easy review (#4, reference).

In words, failed and hard reviews decrease the rate of exponential growth of intervals. Ok reivews maintain it. Easy reviews increase the rate of growth.

@e2-71828
Copy link

@fasiha, It's unintuitive, but max(1300, ...) ensures the minimum value is 1300:

  • max(1300, 100) = 1300
  • max(1300, 2000) = 2000

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