File size: 1,521 Bytes
29baa44
 
 
 
ae3d87c
29baa44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Forgetting model used for spaced repetition.

Recall probability decays exponentially, R = exp(-days / S), where the memory
stability S (in days) grows with successful practice and mastery, the same shape as
half-life regression (Settles & Meeder, 2016) with hand-set coefficients.

Forgetting is applied at *read* time to produce an "effective" mastery; it is never
written back to the database, so repeated reads don't compound decay.
"""
import math
from datetime import datetime

REVIEW_RECALL_THRESHOLD = 0.7


def stability_days(practice_count, correct_count, mastery):
    correct_count = correct_count or 0
    practice_count = practice_count or 0
    wrong = max(0, practice_count - correct_count)
    return max(0.5, 1.0 + 1.6 * correct_count ** 0.85 - 0.3 * wrong ** 0.7) * (0.5 + mastery)


def recall_probability(last_practiced, practice_count, correct_count, mastery, now=None):
    if not last_practiced or not practice_count:
        return 1.0
    now = now or datetime.utcnow()
    days = max(0.0, (now - last_practiced).total_seconds() / 86400)
    return math.exp(-days / stability_days(practice_count, correct_count, mastery))


def effective_mastery(mastery, recall):
    # Forgotten knowledge is easier to relearn than new material, so it never decays to zero.
    return mastery * (0.35 + 0.65 * recall)


def days_until_review(practice_count, correct_count, mastery, threshold=REVIEW_RECALL_THRESHOLD):
    return -math.log(threshold) * stability_days(practice_count, correct_count, mastery)