Link to home
Start Free TrialLog in
Avatar of Xhs
Xhs

asked on

Imiting The Facebook News Feed Algorithm Formula

Hello, I am asked to make an existing basic newsfeed code in PHP a little smarter. Maybe with relevancy and diversity. The client is not sure himself, he just wants something smart (kinda) like Facebook's newsfeed  . I found this (maybe outdated but have some clue)

 http://sproutsocial.com/insights/wp-content/uploads/2015/01/Screen-Shot-2015-01-08-at-5.17.46-PM.png

Where:

Sigma – The sum of each individual edge. An edge is a story that can show up in your News Feed, like a status update, comment, Like, tag, and so on.

u – The affinity score. This is the factor that weighs how close you are with the person doing the posting. If you frequently interact with the person posting, have several mutual friends, or are related, Facebook is more likely to give that content a higher weight.

w – The weight for this edge. Not all actions are considered equal in the eyes of Facebook’s algorithm. For example, a friend creating a status update would carry more weight than someone simply liking a status update.

d – The time decay factor. As a posts gets older, it’s more likely that it has already been seen or that it is no longer as relevant. Facebook remedies both of these problems by taking the age of the post into consideration.

I guess that formula is very abstract, and here is my interpretation of it:

    function calculateFeedScore (){
        foreach ($edges as $edge){
            $friendshipWeight = 30 // pre calculated from the DB
            if ($edgeType = comment) $edgeWeight = 1;
            if ($edgeType = like) $edgeWeight = 2;
            if ($edgeType = tag) $edgeWeight = 3;
            .....
            $edgeAgeInDay = ...; // decay each day
            $decay = 0.5 // Radioactive  decay ??
            $edgeDecayFactor =  1 * pow($decay ,$edgeAgeInHour+1 )  // decay after one day
            $edgeScore = friendshipWeight  * $edgeWeight  *$edgeDecayFactor  
            $feedItemScore += $edgeScore;

         }
        return $feedItemScore
    }
 
     
So I just multiply u, w and d. Is that correct? How can I improve it? Yes, I know I need to fine tune it in Production but... Thanks
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial