# — RSyvarth

## Friend Affinity: Determining Love With an Equation

Whilst redesigning the News Feed solution for Duxter (a topic which I will cover later) we ran into the issue of algorithmically assigning a numerical value to the importance of a post so we can determine whether or not it “deserves” to be displayed on the feed. One of the major factors which we have isolated in our equation is essentially how much you like that person which we call the Friend Affinity Factor (μ). This affinity factor (in theory) will let us decide on how important that person’s posts are to a specific user and how likely they are to be interested in them. The issue with this is that relationships are rather inconsistent between people and it is difficult to distill all of the different factors affecting those interactions down to a single value, we did tried it anyways.

The basic idea behind our ranking system is that every single interaction that two users have on site (and hopefully off site at some point) will be logged and weighted based on how important we deem that reaction to be. For example, liking someone’s status may be worth 1 point while playing a game with them could be worth 5 points. These activity logs will then be summed to form two different values. The first number is a rolling sum of all of the interactions within the last 30 days, the Recent Affinity Sum (Ar), and the second is the total interaction sum divided by the number of months the users have been friends, the Total Affinity Sum (At). The reason to include both values in the calculation of μ is so that both long term and new relationships have a chance of appearing on the feed (although new relationships have a slightly higher weight). The issue with the system of pure summation is that there is a chance that a single user’s Affinity Sum will get so high that only content from that single user will ever be shown on the feed. To combat this issue both the Ar and At values are scaled before they are used to calculate the μ value.

An example of the Arctan parent function

The two main goals of the scaling function are to limit the extreme Affinity Sum values and to maintain the separation between the majority of the users with average Affinity Sums. With these two purposes in mind the Arctan function was selected to be the parent function for this scaling equation. Arctan meets both of these requirements as it has both upper and lower limits which would prevent extreme values from skewing the μ calculation and it has a relatively constant slope on both sides of its inflection point which maintains the separation between most of the inner values for Affinity Sums. From the parent Arctan function several transformations were made in order to make the general tenancies of the function work as we needed for it to scale our summation values. Firstly the entire equation was translated up by π/2 to prevent negative values from being generated and to the right so that the “active” parts of the function are within the first quadrant. From this point various other minor transformations are made so that the resultant value is within the desired range for our applications.

The scaled values of Ar and At are then included in a weighted average to create the final μ value which is used in the rest of the news feed entry rating algorithm. The final equation for this reaction is shown below.

Final Friend Affinity Equation

θr = Weight of Recent Affinity Term

θt = Weight of Total Affinity Term

α = Series whose sum is equal to the user’s Affinity Sum

σ = Relative weight of the Affinity Sum (vertical streching)

ω = Horizontal tansformation

ε = Vertical stretch factor, value here will be the max value for the function

I hope you enjoyed this post (and that you are not too confused)! There will be more coming soon!