Trending algorithm based on the article "Trending at Instagram"
Trending algorithm based on the article Trending at Instagram. To detect trends an items current behavior is compared to its usual behavior. The more it differes the higher / lower the score. Items will start trending if the current usage is higher than its average usage. To avoid items quickly become non-trending again the scores are smoothed.
Uses a time series for each item to keep track of its past behavior and get recent behavior with small granularity. Computes the Kullback-Leibler divergence between recent behavior and expected, i.e. past, bahavior. Then blends the current item score with its past decayed maximum score to get the final score.
import "github.com/codesuki/go-trending"
...
scorer := trending.NewScorer()
Parameters
TimeSeries
objectsimport "github.com/codesuki/go-trending"
...
func NewTimeSeries(id string) TimeSeries {
// create time series that satisfies the TimeSeries interface
return timeSeries
}
...
scorer := trending.NewScorer(
WithTimeSeries(NewTimeSeries),
WithHalflife(time.Hour),
WithRecentDuration(time.Minute),
WithStorageDuration(7 * 24 * time.Hour),
)
import "github.com/codesuki/go-trending"
...
scorer := trending.NewScorer()
scorer.AddEvent("id", time)
// add more events. maybe using an event stream.
...
trendingItems := scorer.Score()
GoDoc is located here
go-trending is MIT licensed.