为了在Android中开发一个词汇表练习应用程序,我想在Java中实现SuperMemo (SM-2)算法。这是一个流行的选择间隔重复软件和Anki甚至采用它,据我所知。给出这里的源代码示例很难理解(对我来说),因为缺乏代码格式,而且它是用Delphi编写的。
SuperMemo 州的作者:
下面是关于堆栈溢出的一些相关(但不同的)问题:
如何在Java中实现这一点?
(我最近一直在做这件事,我想我有一个答案,所以我把它作为一对问答来提出,以帮助其他人做同样的事情。)
发布于 2018-03-01 10:03:35
SuperMemo算法
以下是我们在影响SuperMemo (SM-2)算法 of 间隔重复时要处理的一些条款。
0表示他们还没有研究过,1表示这是他们的第一次,依此类推。在一些文档中,它也被称为n。0到5。1.3到2.5。默认值
int repetitions = 0;
int interval = 1;
float easiness = 2.5;代码
我发现这个Python实现比SuperMemo示例源代码更容易理解,所以我或多或少地遵循了这一点。
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 millisecondsInDay = 60 * 60 * 24 * 1000;
long now = System.currentTimeMillis();
long nextPracticeDate = now + millisecondsInDay*interval;
// Store the nextPracticeDate in the database
// ...
}备注
easiness设置上限。应该是2.5吗?文档和源代码似乎相互矛盾。https://stackoverflow.com/questions/49047159
复制相似问题