| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
FSRS.Algorithm
Description
The FSRS-7 memory model.
This module is a direct transcription of the finished FSRS-7, whose
reference implementation is the Rust model its author signed off on:
https://github.com/Expertium/fsrs-rs-speed-autoresearch (see
fsrs-rs/src/model.rs), upstreamed in
fsrs-rs#426.
Every function here is pure and total.
What changed in FSRS-7 relative to FSRS-6:
- A card carries two memory traces instead of one — see
MemoryState. The forgetting curve is a mixture of a fast and a slow component, one per trace, and each trace is updated by its own block of weights. This is what makes same-day reviews behave differently from spaced ones; FSRS-6 switched between two formulas on a same-day/not-same-day flag. - The forgetting curve depends on difficulty, which it never did before: a hard card experiences time faster, and counts the slow trace for more.
- Post-lapse stability no longer depends on difficulty.
- A lapse's difficulty step is weighted by how surprising the lapse was —
see
nextDifficulty. - Retrievability is squeezed into
[1e-5, 1 - 1e-5], so a card reviewed a moment ago has a retrievability just short of1. - Intervals are genuinely continuous. Ten minutes is
10 / 1440days and the model is meant to be evaluated at such values, not at whole days.
Synopsis
- retrievability :: Parameters -> Days -> MemoryState -> Retrievability
- retrievabilityDerivative :: Parameters -> Days -> MemoryState -> Double
- fastTraceRetrievability :: Parameters -> Days -> Stability -> Retrievability
- nextIntervalDays :: Parameters -> Retrievability -> MemoryState -> Days
- initialDifficulty :: Parameters -> Rating -> Difficulty
- nextDifficulty :: Parameters -> Difficulty -> Retrievability -> Rating -> Difficulty
- initialStability :: Parameters -> Rating -> Stability
- stabilityAfterReview :: StabilityWeights -> Stability -> Difficulty -> Retrievability -> Rating -> Stability
- nextStability :: Parameters -> MemoryState -> Days -> Rating -> (Stability, Stability)
- initialMemoryState :: Parameters -> Rating -> MemoryState
- nextMemoryState :: Parameters -> Maybe MemoryState -> Days -> Rating -> MemoryState
- replayReviews :: Parameters -> [(Days, Rating)] -> Maybe MemoryState
- stabilityMin :: Stability
- stabilityMax :: Stability
- difficultyMin :: Difficulty
- difficultyMax :: Difficulty
- minimumIntervalDays :: Days
- maximumIntervalDays :: Days
- retrievabilityFloor :: Retrievability
- fastTraceRatio :: Double
Forgetting curve
retrievability :: Parameters -> Days -> MemoryState -> Retrievability Source #
The probability of recalling a card t days after the last review.
FSRS-7 mixes a fast-trace and a slow-trace power law, so this needs the
whole memory state — both stabilities and the difficulty. The weight of
each component depends on its own stability, so — unlike every earlier
version — the retrievability at t == s is not a fixed 0.9.
t is treated as 0 if negative; the state is clamped into range, so any
finite state is safe.
retrievabilityDerivative :: Parameters -> Days -> MemoryState -> Double Source #
d/dt of retrievability. Never positive for in-bounds parameters.
fastTraceRetrievability :: Parameters -> Days -> Stability -> Retrievability Source #
The fast trace's own recall probability — the mixture's fast component on its own, unrescaled and with no contribution from the slow trace.
This is what drives the fast trace's stability update in nextStability:
the fast trace responds to how well it was doing, not to the mixture.
nextIntervalDays :: Parameters -> Retrievability -> MemoryState -> Days Source #
The interval, in days, after which a card in the given state will have decayed to exactly the desired retention.
The FSRS-7 forgetting curve has no closed-form inverse, so this is a
root-find: Newton's method in log t (which is what makes the problem
well-conditioned), safeguarded by a bracketing bisection so that it cannot
diverge.
The result is always within [;
a desired retention that is unreachable within that window saturates at the
nearer end. Since retrievability tops out just below minimumIntervalDays, maximumIntervalDays]1, a target of 1
saturates rather than diverging.
Difficulty
initialDifficulty :: Parameters -> Rating -> Difficulty Source #
The difficulty a card is born with, given the rating of its first review.
Arguments
| :: Parameters | |
| -> Difficulty | |
| -> Retrievability | The retrievability at review time, from |
| -> Rating | |
| -> Difficulty |
Difficulty after a review: a rating-driven step, damped so that it slows
down as difficulty approaches its maximum, then reverted 1% of the way
towards the difficulty an Easy first review would have produced.
A lapse's step is weighted by how surprising the lapse was, which is why this takes the retrievability at review time: forgetting a card the model expected you to recall says more about the card than forgetting one that was long overdue.
Stability
initialStability :: Parameters -> Rating -> Stability Source #
The stability a card is born with, given the rating of its first review.
Arguments
| :: StabilityWeights | |
| -> Stability | The stability of the trace being updated. |
| -> Difficulty | |
| -> Retrievability | That trace's retrievability at review time. |
| -> Rating | |
| -> Stability |
One trace's stability update.
Called twice per review — once with slowTraceWeights and
once with fastTraceWeights — on that trace's own stability
and its own retrievability.
On a lapse the new stability is the post-lapse stability, which can never exceed the old one and, in the finished FSRS-7, does not depend on difficulty. On a success it is the old stability scaled by a factor that grows with how overdue the card was, shrinks as the card gets easier and more stable, and is scaled again by the hard penalty or the easy bonus.
Arguments
| :: Parameters | |
| -> MemoryState | |
| -> Days | Days since the previous review. |
| -> Rating | |
| -> (Stability, Stability) |
Both stabilities after a review, as (slow, fast).
The slow trace is updated from the mixed retrievability; the fast trace
from its own fastTraceRetrievability. On a lapse the fast trace is pulled
down to at most fastTraceRatio of the post-lapse slow stability, so that
forgetting a card cannot leave it with a large short-term boost.
State transition
initialMemoryState :: Parameters -> Rating -> MemoryState Source #
The state a card is born with, given the rating of its first review. The
fast trace starts at fastTraceRatio of the slow one.
Arguments
| :: Parameters | |
| -> Maybe MemoryState | The state before the review, or |
| -> Days | Days since the previous review. |
| -> Rating | |
| -> MemoryState |
Advance a card's memory state by one review.
Pass Nothing for a card that has never been reviewed; the elapsed time is
then ignored and the state comes from initialMemoryState.
replayReviews :: Parameters -> [(Days, Rating)] -> Maybe MemoryState Source #
Fold a whole review history into a memory state.
Each element is (days since the previous review, rating); the elapsed time
of the first review is ignored. Nothing for an empty history.
Bounds
stabilityMin :: Stability Source #
The smallest stability the model will report, 1e-4 days (about nine
seconds). FSRS-7 is always run with second-precision intervals.
stabilityMax :: Stability Source #
The largest stability the model will report: 36500 days, a century.
difficultyMin :: Difficulty Source #
1.
difficultyMax :: Difficulty Source #
10.
minimumIntervalDays :: Days Source #
One second, expressed in days — the shortest interval nextIntervalDays
will return.
maximumIntervalDays :: Days Source #
A century in days — the longest interval nextIntervalDays will return.
retrievabilityFloor :: Retrievability Source #
1e-5. retrievability is rescaled into
[ so that neither it nor
its logarithm can saturate.retrievabilityFloor, 1 - retrievabilityFloor]
fastTraceRatio :: Double Source #
0.8. The fast trace starts at this fraction of the slow one, and after a
lapse is pulled back down to at most this fraction of it.