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 an
Here are some terms that we will deal with when impementing the SuperMemo (SM-2) algorithm of spaced repetition.
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.0
to 5
.1.3
to 2.5
.int repetitions = 0;
int interval = 1;
float easiness = 2.5;
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 millisecondsInDay = 60 * 60 * 24 * 1000;
long now = System.currentTimeMillis();
long nextPracticeDate = now + millisecondsInDay*interval;
// Store the nextPracticeDate in the database
// ...
}
easiness
. Should it be 2.5
? The documentation and source code seemed to contradict each other.