Pages

Sunday 11 March 2012

Algorithm for facemash


You must be remembering this scene from The Social Network movie,when Eduardo Saverin writes an algorithm for making facemash.com.

Actually,the algorithm is a simple algorithm to rank the players of chess,named Elo rating System.According to wiki:


The Elo rating system is a method for calculating the relative skill levels of players in two-player games such as chess.

Algorithm:

According to this algorithm following represents the expected score of for example,Player A








Similarly the expected score for example,Player B is:


Where RA is current rating of Player A and RB is current rating of player B.

When player A will play the match whatever score he has,it will be compared with the expected score and that will give a new rating for player A. This will be done using the below formula;




Where SA is the actual score of player A. K is a constant that has two values for Master players K=16 and for weaker players K will be 32.

Let us take an example of rating girls as done in the Social Network movie. For example we have the following table:


Girl Current Rating Result Score


A


80




B


90
Lost 0


C


30
Won 1


D


50
Draw 0.5


E


40
Won 1


Now as you can see clearly that A was compared with 4 girls and she has scored 2.5 points. If you calculate the expected score using the above formula it will be as follows :
                    
                     2.157(0.485+0.572+0.543+0.557).

Now using the second formula given above we will calculate the new Rating for player A  using K = 16  will be

                     R’A = 80 + 16(2.5-2.157) = 85.2

That's all about the algorithm.Anything more should be reflected in comments.




3 comments: