File size: 1,224 Bytes
2f2df6d | 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 40 41 42 43 44 45 46 47 48 49 | from __future__ import annotations
import math
import random
from .schema import ForgettingParams, RecallLabel
def compute_stability(
memory_tendency: float,
importance: float,
arousal: float,
n_rehearsals: int,
params: ForgettingParams,
) -> float:
"""
Ebbinghaus-inspired stability formula (exp_stability_v1):
S = S0 * tendency * (1 + a*importance) * (1 + b*arousal) * (1 + c)^n_rehearsals
"""
s = (
params.S0_days
* memory_tendency
* (1.0 + params.a_importance * importance)
* (1.0 + params.b_arousal * arousal)
* ((1.0 + params.c_rehearsal) ** n_rehearsals)
)
return round(s, 4)
def compute_p_recall(days_since_last_rehearsal: float, stability: float) -> float:
"""Exponential forgetting curve: p_recall = exp(-days / S)."""
if stability <= 0:
return 0.0
p = math.exp(-max(days_since_last_rehearsal, 0.0) / stability)
return round(p, 6)
def sample_recall_label(
p_recall: float,
partial_band: float,
rng: random.Random,
) -> RecallLabel:
u = rng.random()
if u < p_recall:
return "full"
if u < p_recall + partial_band:
return "partial"
return "forgotten"
|