SuperMemo(SM-2)的间隔重复算法 [英] Spaced repetition algorithm from SuperMemo (SM-2)

查看:1849
本文介绍了SuperMemo(SM-2)的间隔重复算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在Android中制作词汇练习应用程序,我想实现 SuperMemo Java中的(SM-2)算法。这是间隔重复软件的流行选择,Anki甚至按照我的理解采用它。 此处给出的源代码示例很难(对我而言)因为缺乏代码格式,因为它是用Delphi编写的。

In order to make a vocabulary practice app in Android, I want to implement the SuperMemo (SM-2) algorithm in Java. This is a popular choice for spaced repetition software and Anki even adopts it as I understand. The source code example given here was difficult (for me) to follow because of the lack of code formatting and because it is written in Delphi.

SuperMemo的作者

The author of SuperMemo states:



  1. 拆分知识最小可能项目。

  2. 所有项目关联的E系数等于2.5。

  3. 使用以下间隔重复项目:
    I(1):= 1

    I(2):= 6

    ,n> 2:I(n):= I(n-1)* EF

    其中:

    I(n) - 第n次重复后的重复间隔(以天计),

    EF - 给定项目的E系数< br>
    如果interval是一个分数,则将其四舍五入到最接近的整数。

  4. 每次重复后,按0-5等级评估重复反应的质量:
    5 - 完美回复

    4 - 犹豫后正确回应< br>
    3 - 正确回答严重困难

    2 - 错误回复;哪一个似乎很容易回忆起来?
    1 - 不正确的反应;记得正确的人:
    0 - 完全停电。

  5. 每次重复后,根据以下公式修改最近重复项目的E因子:

    EF':= EF +(0.1-(5-q)* (0.08+(5-q)* 0.02))

    其中:

    EF' - E因子的新值,

    EF - 旧值E因子,

    q - 0-5等级的响应质量。

    如果EF小于1.3,那么让EF为1.3。

  6. 如果质量响应低于3,则从头开始重复项目而不更改E因子(即使用
    区间I(1),I(2)等等,好像该项目被重新记忆)。

  7. 在某一天的每次重复会话之后,再次重复质量评估中得分低于4的所有项目。继续
    重复,直到所有这些项目得分至少为4。

  1. Split the knowledge into smallest possible items.
  2. With all items associate an E-Factor equal to 2.5.
  3. Repeat items using the following intervals: I(1):=1
    I(2):=6
    for n>2: I(n):=I(n-1)*EF
    where:
    I(n) - inter-repetition interval after the n-th repetition (in days),
    EF - E-Factor of a given item
    If interval is a fraction, round it up to the nearest integer.
  4. After each repetition assess the quality of repetition response in 0-5 grade scale: 5 - perfect response
    4 - correct response after a hesitation
    3 - correct response recalled with serious difficulty
    2 - incorrect response; where the correct one seemed easy to recall
    1 - incorrect response; the correct one remembered
    0 - complete blackout.
  5. After each repetition modify the E-Factor of the recently repeated item according to the formula:
    EF':=EF+(0.1-(5-q)*(0.08+(5-q)*0.02))
    where:
    EF' - new value of the E-Factor,
    EF - old value of the E-Factor,
    q - quality of the response in the 0-5 grade scale.
    If EF is less than 1.3 then let EF be 1.3.
  6. If the quality response was lower than 3 then start repetitions for the item from the beginning without changing the E-Factor (i.e. use intervals I(1), I(2) etc. as if the item was memorized anew).
  7. After each repetition session of a given day repeat again all items that scored below four in the quality assessment. Continue the repetitions until all of these items score at least four.


这里有Stack Overflow上的一些相关(但不同)的问题:

Here are some related (but different) questions on Stack Overflow:

  • What is the spaced repetition algorithm to generate the day intervals?
  • Open Source implementation of a Spaced Repetition Algorithm in Java
  • Spaced repetition (SRS) for learning

如何用Java实现这个?

How do you implement this in Java?

(我最近一直在研究这个问题,我想我有一个答案,所以我提交这个作为Q& A对来帮助其他人做同样的事情。)

推荐答案

SuperMemo算法



以下是我们在强制执行 SuperMemo(SM-2)算法时要处理的一些术语 间隔重复


  • 重复 - 这是用户看到闪卡的次数。 0 表示他们尚未研究过, 1 表示这是他们的第一次,依此类推。在某些文档中,它也被称为 n

  • 质量 - 也称为质量评估。这是闪存卡的难度(由用户定义)。比例从 0 5

  • easiness - 这也称为容易因子或EFactor或EF。它是乘数,用于增加间隔重复的空间。范围从 1.3 2.5

  • interval - 这是重复之间的时间长度(以天为单位)。这是间隔重复的空间。

  • nextPractice - 这是日期/时间

  • repetitions - this is the number of times a user sees a flashcard. 0 means they haven't studied it yet, 1 means it is their first time, and so on. It is also referred to as n in some of the documentation.
  • quality - also known as quality of assessment. This is how difficult (as defined by the user) a flashcard is. The scale is from 0 to 5.
  • easiness - this is also referred to as the easiness factor or EFactor or EF. It is multiplier used to increase the "space" in spaced repetition. The range is from 1.3 to 2.5.
  • interval - this is the length of time (in days) between repetitions. It is the "space" of spaced repetition.
  • nextPractice - This is the date/time of when the flashcard comes due to review again.
int repetitions = 0;
int interval = 1;
float easiness = 2.5;



代码



我发现这个Python实现 SuperMemo示例源代码,所以我或多或少都遵循这一点。

Code

I found this Python implementation somewhat easier to follow than the SuperMemo example source code, so I am more or less following that.

private void calculateSuperMemo2Algorithm(FlashCard card, int quality) {

    if (quality < 0 || quality > 5) {
        // throw error here or ensure elsewhere that quality is always within 0-5
    }

    // retrieve the stored values (default values if new cards)
    int repetitions = card.getRepetitions();
    float easiness = card.getEasinessFactor();
    int interval = card.getInterval();

    // easiness factor
    easiness = (float) Math.max(1.3, easiness + 0.1 - (5.0 - quality) * (0.08 + (5.0 - quality) * 0.02));

    // repetitions
    if (quality < 3) {
        repetitions = 0;
    } else {
        repetitions += 1;
    }

    // interval
    if (repetitions <= 1) {
        interval = 1;
    } else if (repetitions == 2) {
        interval = 6;
    } else {
        interval = Math.round(interval * easiness);
    }

    // next practice 
    int secondsInDay = 60 * 60 * 24;
    long now = System.currentTimeMillis();
    long nextPracticeDate = now + secondsInDay*interval;

    // Store the nextPracticeDate in the database
    // ...
}



注释




  • 上面的代码没有设置 easiness <的上限/ code>。应该是 2.5 ?文档和源代码似乎相互矛盾。

  • 如果质量评估小于3,文档也说得不容易更新,但这似乎是矛盾的源代码。在我看来,更新它更有意义(只要它保持在1.3以上)。无论如何,我每次都在更新它。

  • Anki源代码是这里。不过,这是一个很大的项目,我还没有深入挖掘它们的算法版本。

  • 这篇文章讨论了SM-2的一些问题以及这些问题的解决方案。

  • Notes

    • The code above does not set an upper limit on easiness. Should it be 2.5? The documentation and source code seemed to contradict each other.
    • The documentation also made it sound like the easiness factor should not be updated if the quality assessment was less than 3, but this seems to contradict the source code. It also seems to me to make more sense to update it (as long as it is kept above 1.3). Anyway, I am updating it every time.
    • The Anki source code is here. It is a big project, though, and I haven't dug down deep enough yet to see their version of the algorithm.
    • This post talks about some problems with SM-2 and solutions for those problems.
    • 这篇关于SuperMemo(SM-2)的间隔重复算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆