Skip to content

Learning Algorithm

Yuxuan Chen edited this page Oct 26, 2020 · 4 revisions

Intuition

  1. Finishing the reviews two times in a row masters a character, if there is an incorrect answer, the bar should be lifted one by one up to a certain limit (MAX_IN_A_ROW_REQUIRED)
  2. The two fields of a single character are separated
  3. There need to be some kinds of spaced-repetition, which means: i. one character shouldn't be reviewed too soon after it is learned ii. the more times one character is learned, the longer should be its interval of learning this is done through the weighted_duration and reviewing the field of the character with the longest weighted_duration
  4. There shouldn't be too many or too few characters that are learned at the same time. This is done through keeping the number of in progress (reviewable) characters in the range [MIN_UC_IN_PROGRESS_CNT, MAX_UC_IN_PROGRESS_CNT], and tuning LEARN_PROB

below will introduce the details

Constants (to be tuned):

DEFAULT_IN_A_ROW_REQUIRED = 2
MAX_IN_A_ROW_REQUIRED = 2
ADDED_DURATION = 30 # seconds
MIN_UC_IN_PROGRESS_CNT = 3
MAX_UC_IN_PROGRESS_CNT = 8
LEARN_PROB = 1 / 3

variable explanation

Each character has two test fields (pinyin and definition_1), for each field, there are a number of variables that we store:

  1. in_a_row (default: 0): the number of correct answers in a row for this field
  2. in_a_row_required (default: DEFAULT_IN_A_ROW_REQUIRED): the user needs this many corrects in a row to be considered mastering this field
  3. last_study_duration: the time between last study and now
  4. mastered: whether in_a_row == in_a_row_required

Each character has two variables to itself:

  1. learned: whether the user has started learning this character
  2. mastered: wheter both test fields are mastered

term definition

learnable: not learned
reviewable: learned but not mastered

Learning states and transitions

Please think of the learning process as a state machine, starting from Transition

state 1: Transition

if all characters are mastered, goto Finish
if (no learnable character) or (there are >= MAX_UC_IN_PROGRESS_CNT reviewable character): goto Test_review
if (there are <= MIN_UC_IN_PROGRESS_CNT): goto Learn
otherwise, goto Learn with probability LEARN_PROB, goto Test_review with probability 1 - LEARN_PROB

State 2: Learn

Randomly select a learnable character
goto Tolerant_review(character)

State 3: Re-learn(character)

Display character
goto Transition

State 4: Tolerant_review(character)

Test both test fields of character, even if user answers anything wrong, do nothing
goto Transition

State 5: Test_review

  • assume all time units are in seconds

Select the reviewable field of a character that maximizes its
weighted_duration = last_study_duration / (in_a_row + 1) + ADDED_DURATION
test the field of the character

if the user answers correctly:

  1. steps up in_a_row, masters the field and the character if applicable
  2. goto Transition
    else if the user answers incorrectly:
  3. in_a_row = 0
  4. steps up in_a_row_required, up to MAX_IN_A_ROW_REQUIRED
  5. goto Relearn(character)

State 6: Finish