If you wondered what that highly complicated and fancy Algorithm on the Social Network movie is wonder no more.
Turns out it the common rating algorithm often used in chess called the Elo rating system.
After some Googling (yes its a verb), it would appear that the Facemash algorithm corresponds to the Elo rating system. Thus, the equations involved are:
see wikipedia for more explaination or http://gobase.org/studying/articles/elo/ for another good explanation
Apparently programmers write the code on the window of the dorms personally I've never done that I just write it on my blog. Anywho.
The class is below written in C# it uses a constant of 400 you can adjust this if you like
public class EloRating
{
public double Point1 { get; set; }
public double Point2 { get; set; }
public double FinalResult1 { get; set; }
public double FinalResult2 { get; set; }
public EloRating(double CurrentRating1, double CurrentRating2, double Score1, double Score2)
{
/*
double CurrentR1 = 1500.0;
double CurrentR2 = 1500.0;
double Score1 = 20.0;
double Score2 = 10;
*/
double E = 0;
if (Score1 != Score2)
{
if (Score1 > Score2)
{
E = 120 - Math.Round(1 / (1 + Math.Pow(10, ((CurrentRating2 - CurrentRating1) / 400))) * 120);
FinalResult1 = CurrentRating1 + E;
FinalResult2 = CurrentRating2 - E;
}
else
{
E = 120 - Math.Round(1 / (1 + Math.Pow(10, ((CurrentRating1 - CurrentRating2) / 400))) * 120);
FinalResult1 = CurrentRating1 - E;
FinalResult2 = CurrentRating2 + E;
}
}
else
{
if (CurrentRating1 == CurrentRating2)
{
FinalResult1 = CurrentRating1;
FinalResult2 = CurrentRating2;
}
else
{
if (CurrentRating1 > CurrentRating2)
{
E = (120 - Math.Round(1 / (1 + Math.Pow(10, ((CurrentRating1 - CurrentRating2) / 400))) * 120)) - (120 - Math.Round(1 / (1 + Math.Pow(10, ((CurrentRating2 - CurrentRating1) / 400))) * 120));
FinalResult1 = CurrentRating1 - E;
FinalResult2 = CurrentRating2 + E;
}
else
{
E = (120 - Math.Round(1 / (1 + Math.Pow(10, ((CurrentRating2 - CurrentRating1) / 400))) * 120)) - (120 - Math.Round(1 / (1 + Math.Pow(10, ((CurrentRating1 - CurrentRating2) / 400))) * 120));
FinalResult1 = CurrentRating1 + E;
FinalResult2 = CurrentRating2 - E;
}
}
}
Point1 = FinalResult1 - CurrentRating1;
Point2 = FinalResult2 - CurrentRating2;
}
}
By C# Elo Rating Class used on Facemash November 7, 2010 - 5:08 pm
[...] Durrant has posted the C# Elo Rating class used for Facemash.com.au. http://lukedurrant.com/2010/11/c-elo-rating-class-used-on-facemash-as-seen-in-the-social-network-mov… Elo [...]
By Daniel Budd November 25, 2010 - 2:52 pm
Any updates on the site since you last wrote the original code?
By Luke Fitzgerald December 29, 2010 - 1:11 am
What is the point in the ternary operator on lines 59/60 when the true/false operations are the same?
By luke December 29, 2010 - 11:53 am
the calculations have to be done on both Point1 and Point2
check the variable names are all different you’ll see what I mean
By Michael December 31, 2010 - 10:13 pm
Point1 = (((FinalResult1 – CurrentRating1) > 0) ? (FinalResult1 – CurrentRating1) : (FinalResult1 – CurrentRating1));
Point2 = (((FinalResult2 – CurrentRating2) > 0) ? (FinalResult2 – CurrentRating2) : (FinalResult2 – CurrentRating2));
can be simplified to:
Point1 = FinalResult1 – CurrentRating1;
Point2 = FinalResult2 – CurrentRating2;
It doesn’t matter if (FinalResult1 – CurrentRating1) or (FinalResult2 – CurrentRating2) is positive or not.
By luke January 1, 2011 - 1:29 pm
ah good point that’s me being to careful with negative numbers and divide by zero exception (I know no divide to be seen)
By Luke Andrews January 3, 2011 - 11:13 pm
How could I use this code sorry for the novice question I
am new to all this and found the facemash a brilliant concept and
if we could redevelop it and get a lot of traffic
By Terez January 17, 2011 - 9:32 am
Hi, nice work!
I have a question though. Is it possible to grow the database of the people over the time? I mean lets say that the facemash is already running a month, then you want to add next 20people to the system. What happens? If I understand it well, then you assign every new person some fixed rating – e.g. 1500. So now we have in a system people, that already have been in numerous duels and have a rating lets say 900 even though they look obvisously better then the new ones. How long will it take before the results of the newly added people become objective? How do you pick profiles that will be taken to the duel? Is it absolutely random, or do you have some kind of a system?
Thanks in advance for a reply, this is realy an interesting topic for me.
Terez.
By luke January 19, 2011 - 4:46 pm
Yes the “duel” is completely random.
How long it takes depends on how many people you have voting and how many votes they are making.
You should let the algorithm do the work if you are removing contestants then its not going to be as natural.
By What do you do when you can’t afford 30k for Facemash.com? | Luke Durrant January 19, 2011 - 4:53 pm
[...] I even wrote a C# class of the Elo rating algorithm [...]
By Cam Pedersen January 31, 2011 - 3:35 pm
Hey man, I made a site similar to yours before I found out about it. Check out mugshotwars and leftright
You might be interested in my Javascri
By Xavier March 20, 2012 - 1:35 pm
can you send me the link for your site?
By Tony March 17, 2011 - 9:20 am
Could I wrote this code in the Visual C# program by Microsoft? And if so, how do I publish it into my website?
By luke April 5, 2011 - 11:41 am
Yes you’ll need to download Visual Studio 2010 Express, its free!
By angelkorn January 18, 2012 - 12:24 am
Hey Man,
How can I come up with this problem in voting system using your Elo Rating Class?
“Image 1 was voted for over Image 2 86% of the time”
and generate display:
Top 20 Image:
Image 1 96% (over image 7)
Image 4 92% (over image 3)
Image 3 84% (over image 2)
etc.
Please help me…
Thanks
By Facemash fool proofing your code, don’t count on it | Luke Durrant: Perth, Australia. Developer iPhone/iPad apps and Web applications February 26, 2012 - 12:16 pm
[...] [...]
By Xavier March 20, 2012 - 1:28 pm
why you dont answer? is the question too obvious?
By Xavier March 20, 2012 - 1:23 pm
I’m totally excited about creating a website like this or similar, could you guys help me?
How could I start? What do I need to know? I also checked your own facemash and in some pages I couldnt click on the images!
Thanks
Great site btw.
By luke March 20, 2012 - 1:32 pm
Sure!
The most difficult part is on this page.
What did you need help with exactly?
By xavier March 22, 2012 - 1:24 pm
what software do i need to learn to build a website like face mash? how did you get the pictures in the first place? im totally excited about this
By luke April 1, 2012 - 7:02 pm
You can use any code editor you like! It sounds as though you should attempt a smaller project first.
The pictures are retrieved through the myspace search API.
Enjoy!
By Edwin S June 3, 2012 - 10:18 am
dude, you saved my life