jiaaro / dailybread

Daily Bread - A grocery app optimized for remembering the essentials
http://dailybread.jiaaro.com
12 stars 2 forks source link

Ranking Algorithm 2.0 #10

Closed jiaaro closed 9 years ago

jiaaro commented 10 years ago
jiaaro commented 10 years ago

Sanity checks:

jiaaro commented 10 years ago

// changes a number to it's position along a 0.0 - 1.0 scale
function normalize(x, scale_min, scale_max) {
    return (x - scale_min) / (scale_max - scale_min);
}

/*  …in ranking algorithm…
*/

// 5 times as long as the avg time between adds is how long the boosted
// likelihood lasts. For a weekly item this means it is boosted for 5 weeks
fade_out = 5

if (time_since_last_add < avg_time_between_adds) {
  likelihood *= 0.1 + (1.9 * time_since_last_add / avg_time_between_adds);
}
else if ( ( (fade_out + 1) * time_since_last_add) < avg_time_between_adds) {
  likelihood *= 1.0 + normalize(
      avg_time_between_adds / time_since_last_add,
      1/(fade_out+1), // min
      1.0 // max
  );
}