Skip to content

Learning algorithm

Robert Trzebiński edited this page Apr 16, 2021 · 43 revisions

The purpose of App\Services\LearningService service is to find next exercise to present to a user when he uses the application learning mode.

It detects what is the best exercise to present to a user based on several factors. Question is shown to the user and he is giving either good or bad answer. Verifying the answer depends on the client which has access to both question and answer. In current implementation these are just "good answer" and "bad answer" buttons making suitable call to the app.

When an answer to a given question is registered the following happens:

  • number of good/bad answers is increased by one
  • number of good/bad answers today is increased by one
  • percent od good answers is updated

These results are stored in exercise_results pivot table that is connecting user with exercise and its results.

Based on the above App\Services\PointsCalculator is calculating points for every exercise in lesson being learnt.

Points calculator is assigning each exercise a points value between 0 and 200. The more points the bigger chance for an exercise to be served next. 0 points meaning not possible to serve an exercise. 200 points exercise having 100 times bigger possibility to be served than 1 point exercise.

The following conditions are checked in order:


Exercise is new (never answered) -> 100 points

^^ prioritises new exercises

  • Check for answers today

Both good and bad answers today + good was latest -> 0 points

Only good answer today -> 0 points

^^ prevents already well known exercise from being served same day again

Only bad answers today

Number of bad answers >= config(max_exercise_bad_answers_per_day) -> 0 points (app has a limit of sensible max of bad answers per day to avoid too many repetitions)

If user never had good answer -> 200 points

^^ prioritises new exercises that were already presented during current session

Number of bad answers = 1 -> 80 points

Number of bad answers = 2 -> 50 points

Number of bad answers >= 3 -> 20 points

^^ decrease probability with each bad answer

  • No answers today - check for answers of just one type

Only good answers:

Number of good answers = 1 -> 80 points

Number of good answers = 2 -> 50 points

Number of good answers = 3 -> 20 points

Number of good answers > 3 -> 1 points

^^ decrease probability with each good answer

  • If none of above applied calculate number of points related to percent of good answer:
if ($percentOfGoodAnswers == 100) {
    return 1;
}

return (100 - $percentOfGoodAnswers);

For percent of good answer = 0 return 100 points

For percent of good answer = 100 return 1 point

For percent of good answer = 20 return 80 points

For percent of good answer = 50 return 50 points

For percent of good answer = 90 return 10 points

etc.

^^ prioritise less knows exercise over better known


Based on these points LearningService::findUserExerciseToLearn() will return one weighted random exercise to be presented to the user.

User can then provide the answer and the cycle goes back again.

Clone this wiki locally