From af8f8732f62217c981bee8fa52ace4ed58cea67b Mon Sep 17 00:00:00 2001 From: ishiko Date: Tue, 17 Dec 2024 19:37:30 +0800 Subject: [PATCH] Fix/clip post lapse stability (#142) --- package.json | 2 +- src/fsrs/algorithm.ts | 2 ++ src/fsrs/default.ts | 2 +- src/fsrs/impl/basic_scheduler.ts | 17 +++++++++++++---- src/fsrs/impl/long_term_scheduler.ts | 10 +++++++--- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index e0f9aaa..a0a81c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-fsrs", - "version": "4.5.0", + "version": "4.5.1", "description": "ts-fsrs is a versatile package based on TypeScript that supports ES modules, CommonJS, and UMD. It implements the Free Spaced Repetition Scheduler (FSRS) algorithm, enabling developers to integrate FSRS into their flashcard applications to enhance the user learning experience.", "main": "dist/index.cjs", "umd": "dist/index.umd.js", diff --git a/src/fsrs/algorithm.ts b/src/fsrs/algorithm.ts index 3a24f1a..73aedae 100644 --- a/src/fsrs/algorithm.ts +++ b/src/fsrs/algorithm.ts @@ -233,6 +233,8 @@ export class FSRSAlgorithm { /** * The formula used is : * $$S^\prime_f(D,S,R) = w_{11}\cdot D^{-w_{12}}\cdot ((S+1)^{w_{13}}-1) \cdot e^{w_{14}\cdot(1-R)}$$ + * enable_short_term = true : $$S^\prime_f \in \min \lbrace \max \lbrace S^\prime_f,0.01\rbrace, \frac{S}{e^{w_{17} \cdot w_{18}}} \rbrace$$ + * enable_short_term = false : $$S^\prime_f \in \min \lbrace \max \lbrace S^\prime_f,0.01\rbrace, S \rbrace$$ * @param {number} d Difficulty D \in [1,10] * @param {number} s Stability (interval when R=90%) * @param {number} r Retrievability (probability of recall) diff --git a/src/fsrs/default.ts b/src/fsrs/default.ts index 82c38d1..6902b2f 100644 --- a/src/fsrs/default.ts +++ b/src/fsrs/default.ts @@ -11,7 +11,7 @@ export const default_w = [ export const default_enable_fuzz = false export const default_enable_short_term = true -export const FSRSVersion: string = 'v4.5.0 using FSRS-5.0' +export const FSRSVersion: string = 'v4.5.1 using FSRS-5.0' export const generatorParameters = ( props?: Partial diff --git a/src/fsrs/impl/basic_scheduler.ts b/src/fsrs/impl/basic_scheduler.ts index e3583c6..b0574c0 100644 --- a/src/fsrs/impl/basic_scheduler.ts +++ b/src/fsrs/impl/basic_scheduler.ts @@ -186,11 +186,20 @@ export default class BasicScheduler extends AbstractScheduler { difficulty, Rating.Again ) - next_again.stability = this.algorithm.next_forget_stability( - difficulty, - stability, - retrievability + const nextSMin = + stability / + Math.exp( + this.algorithm.parameters.w[17] * this.algorithm.parameters.w[18] + ) + next_again.stability = Math.min( + +nextSMin.toFixed(8), + this.algorithm.next_forget_stability( + difficulty, + stability, + retrievability + ) ) + next_hard.difficulty = this.algorithm.next_difficulty( difficulty, Rating.Hard diff --git a/src/fsrs/impl/long_term_scheduler.ts b/src/fsrs/impl/long_term_scheduler.ts index 95703ee..5616a9a 100644 --- a/src/fsrs/impl/long_term_scheduler.ts +++ b/src/fsrs/impl/long_term_scheduler.ts @@ -112,11 +112,15 @@ export default class LongTermScheduler extends AbstractScheduler { difficulty, Rating.Again ) - next_again.stability = this.algorithm.next_forget_stability( - difficulty, + next_again.stability = Math.min( stability, - retrievability + this.algorithm.next_forget_stability( + difficulty, + stability, + retrievability + ) ) + next_hard.difficulty = this.algorithm.next_difficulty( difficulty, Rating.Hard