Module: Fsrs::Scheduler::Common

Included in:
Fsrs::Scheduler
Defined in:
lib/fsrs/fsrs.rb

Overview

rubocop:disable Style/Documentation

Instance Method Summary collapse

Instance Method Details

#next_difficulty(d, r) ⇒ Object



385
386
387
388
# File 'lib/fsrs/fsrs.rb', line 385

def next_difficulty(d, r)
  next_d = d - (self.p.w[6] * (r - 3))
  mean_reversion(self.p.w[4], next_d).clamp(1, 10)
end

#next_ds(s, last_d, last_s, retrievability) ⇒ Object



374
375
376
377
378
379
380
381
382
383
# File 'lib/fsrs/fsrs.rb', line 374

def next_ds(s, last_d, last_s, retrievability)
  s.again.difficulty = next_difficulty(last_d, Rating::AGAIN)
  s.again.stability = next_forget_stability(last_d, last_s, retrievability)
  s.hard.difficulty = next_difficulty(last_d, Rating::HARD)
  s.hard.stability = next_recall_stability(last_d, last_s, retrievability, Rating::HARD)
  s.good.difficulty = next_difficulty(last_d, Rating::GOOD)
  s.good.stability = next_recall_stability(last_d, last_s, retrievability, Rating::GOOD)
  s.easy.difficulty = next_difficulty(last_d, Rating::EASY)
  s.easy.stability = next_recall_stability(last_d, last_s, retrievability, Rating::EASY)
end

#next_forget_stability(d, s, r) ⇒ Object



397
398
399
400
# File 'lib/fsrs/fsrs.rb', line 397

def next_forget_stability(d, s, r)
  self.p.w[11] * (d**-self.p.w[12]) * (((s + 1)**self.p.w[13]) - 1) *
    Math.exp((1 - r) * self.p.w[14])
end

#next_interval(s) ⇒ Object



402
403
404
405
# File 'lib/fsrs/fsrs.rb', line 402

def next_interval(s)
  new_interval = s / factor * ((self.p.request_retention**(1 / decay)) - 1)
  new_interval.round.clamp(1, self.p.maximum_interval)
end

#next_recall_stability(d, s, r, rating) ⇒ Object



390
391
392
393
394
395
# File 'lib/fsrs/fsrs.rb', line 390

def next_recall_stability(d, s, r, rating)
  hard_penalty = rating == Rating::HARD ? self.p.w[15] : 1
  easy_bonus = rating == Rating::EASY ? self.p.w[16] : 1
  s * (1 + (Math.exp(self.p.w[8]) * (11 - d) * (s**-self.p.w[9]) *
      (Math.exp((1 - r) * self.p.w[10]) - 1) * hard_penalty * easy_bonus))
end