Facemash algorithm [closed]
Asked Answered
H

8

20

Does anyone know the facemash algorithm that Mark Zuckerberg implemented in his facemash site? http://www.thecrimson.com/article/2003/11/19/facemash-creator-survives-ad-board-the/

Preferably in PHP & MySQL.

Hyperbole answered 3/10, 2010 at 0:5 Comment(0)
K
19

I don't know what algorithm was actually used for the real-world site, but what they write on the window in the movie is based on the Elo rating system, which originated in the chess world and is now also used in many other games.

Karykaryl answered 3/10, 2010 at 0:39 Comment(1)
Thanks! In that case, I found a couple links. PHP: webscripts.softpedia.com/scriptDownload/… & Python: github.com/gak/elo-rating-simulator/blob/master//elo.pyHyperbole
T
29

enter image description here

UPDATE:

As I said in the comments, I've added this algerithm to my new website. At first it seemed to work perfectly. But after some weird inputs some strange result began to form.

While debugging I figured out what I was doing wrong. When getting the score for a "direct relationship" (used in the indirect relationship too) between 2 nodes I added the scores together. This was wrong, the score of a direct relationship should be expressed in -1 to +1, where:

-1 = lost everything 
+1 = won everything

So if A won 8 times to B, and B won 2 times to A the score should be:

(A wins) 8 + (B wins) 2 = (total matches)10
(delta of -1 and +1 =) 2 / (total matches)10 = (points per win) 0.2
Score of A vs B = (points per win) 0.2 * (wins) 8 - 1 = 0.6
Score of B vs A = (points per win) 0.2 * (wins) 2 - 1 = -0.4

Also I didn't mention this in the original explanation but it is all about triangles. So when we look at the indirect score, you don't need to go any further than 1 hop.

Thermidor answered 4/11, 2012 at 21:49 Comment(4)
Hi Peter, I'm in kind of a doubt about sharing this information. In one hand my opinion is that it is information that belongs to humanity, therefore I have to share it with you guys. In het other hand there are really big companies that are looking for something like this to patent in order to use it against people like myself. By keeping it on my own server I can log everybody that looked at the page and will be able to use it in a court room if needed. I am very sorry but I'm keeping it this way.Thermidor
I guess you added the information here anyway. Thanks.Teenateenage
Took the wedsite offline, now using the algeritm in a different project. It still looks like it works correctly.Thermidor
Has anyone implemented this algorithm in php yet?Fluidize
K
19

I don't know what algorithm was actually used for the real-world site, but what they write on the window in the movie is based on the Elo rating system, which originated in the chess world and is now also used in many other games.

Karykaryl answered 3/10, 2010 at 0:39 Comment(1)
Thanks! In that case, I found a couple links. PHP: webscripts.softpedia.com/scriptDownload/… & Python: github.com/gak/elo-rating-simulator/blob/master//elo.pyHyperbole
M
6

I recreated it aswell check it out. Not sure about php but the C# class is

http://lukedurrant.com/2010/11/c-elo-rating-class-used-on-facemash-as-seen-in-the-social-network-movie/

I used it on my

Facemash

Key press code is

$(document).keydown(function(event) {
    if (event.keyCode == 37) {
        //Voted Face 1
        Rate("face1", false);
    } 
    if(event.keyCode == 39) {
        //Voted Face 2
        Rate("face2", false);
    }

});
Mcwilliams answered 8/11, 2010 at 14:46 Comment(4)
It says 'as seen in The Social Network' but it looks really different. In the movie it's with a thick, red header and a white background colour.Reidreidar
how have u implemented the use of keyboard left and right. can you share the code for it ?Ferula
Wow... How did you get so many people using your site? @McwilliamsDevi
Link appears to be a 404. Can you post the code somewhere else?Miscreated
K
4
    <?php
    //This page is responsible to return a JSON object
    //code starts after the functions for those who might get confused xD

    header('content-type: application/json; charset=utf-8');


    global $responseData;


    function AdjustRate($Ra, $Ea, $Sa)
    {
        //i used my own rules here 32 points for less than 500
        if($Ra < 500)
            $k = 32;
        elseif ($Ra < 1000)//24 points for anything between 500 and 1000
            $k = 24;
        else
            $k = 16;//16 for anything more than 1000

        return $Ra + ($k*($Sa - $Ea));
    }

    function GetExpectedChance($rA, $rB) // the ELO formula taken from http://en.wikipedia.org/wiki/Elo_rating_system
    {
        return (1/(1+pow(10,(($rB-$rA)/400))));
    }

    function setNewRates($lastCall) // function I used to update my database tables
    {
        global $responseData;

        $A = $lastCall->p1;
        $B = $lastCall->p2;
        $C = $lastCall->c;
        $A->E = GetExpectedChance($A->rate, $B->rate);
        $B->E = GetExpectedChance($B->rate, $A->rate);

        // decide who won and who lost
        if($A->id == $C){
            $winner = $A;
            $looser = $B;
        }
        elseif ($B->id == $C) {
            $winner = $B;
            $looser = $A;
        }

        // 3 cases, in all of them winner will get his rate/hits increased by 1
        //Case #1: normal case we just update rate/hits for the winner, this applies all the time
        $winner->rate += 1;
        $winner->hits += 1;
        //Case #2 / #3 : here we should adjust the rate after applying case #1
        // if he won while he is expected to lose OR if he lost while expected to win
        // there should be minimum rate different of 40 between the two
        $diff = abs($winner->rate - $looser->rate);
        if($diff >= 40 && ($winner->E < 0.5 || $looser->E >= 0.5)) {
            $winner->rate = AdjustRate($winner->rate, $winner->E, 1);
            $looser->rate = AdjustRate($looser->rate, $looser->E, 0);
        }


        // update the db to update rates, hits for both winner and looser
            $updateQuery = 'UPDATE user SET rate='.$winner->rate.',hits='.$winner->hits.' WHERE id=' . $winner->id;
            mysql_query($updateQuery);

            $updateQuery = 'UPDATE user SET rate='.$looser->rate.' WHERE id=' . $looser->id;
            mysql_query($updateQuery);

        // Save to responsedate
        $responseData->winner = $winner;
        $responseData->looser = $looser;
    }

    //CODE STARTS HERE :)

    // Setup the mysql connection
    include 'db.php';
    // Part 1: calculate the rate and save to db, if we have a lastcall
    // GET the last call data object, it has p1, p2, c, these are the items i recieved from my javascript ajax call
    $lastCall  = json_decode((string)$_GET['lastCall']); // it was a JSON object so i need to decode it first
    // Save last call data, will be sent with the respond as well
    $responseData->lastCall = $lastCall;

    // if there is a json object, means that there was a rating process and I have to set the new rates
    if($lastCall->c != NULL)
    {
        setNewRates($responseData->lastCall);
    }

    // Part 3: Select new persons and addthem to our responseData
    $q = Array();
    $q[0] = 'SELECT id, name, sex, rate, hits FROM user WHERE fm_status=1 AND sex="female" ORDER BY RAND() LIMIT 2';
    $q[1] = 'SELECT id, name, sex, rate, hits FROM user WHERE fm_status=1 AND sex="male" ORDER BY RAND() LIMIT 2';

    // girls or boys ?
    srand(mktime());
    $query = $q[array_rand($q)];
    $result1 = QueryIntoArray($query);
    $responseData->user = $result1;


    // Part 4: encode to JSON/JSONP string then respond to the call
    $json = json_encode($responseData);
    $json = isset($_GET['callback'])? "{$_GET['callback']}($json)" : $json;
    echo $json;

    mysql_close();
    // by Noor Syron :)
    //I used this in my www.mimm.me

    ?>
Kutaisi answered 23/12, 2010 at 16:53 Comment(0)
R
1

`I have designed the code in Perl all from google searching and it works.

Here's It

use strict;
use warnings;
use WWW::Mechanize;
use LWP::Simple;

sub images()
{
my $mech = WWW::Mechanize->new();
my ($site,$count,$file,$dir);
print "\t\t\tDesigned By NUMWARZ GAMING\n\n";
print "Enter the name of the site you want to search for images\t:\n";
$site = <STDIN>;

    print "Enter the folder where you want to save this\t:\n";

    $dir = <STDIN>;

    open my $doc, ">" , $dir."sitelist.txt";

    $mech->get( $site);

    my @links = $mech->images();

    $count = 0;

    for my $link ( @links ) 
    {
    $file = $dir.$count.".jpg";

    mirror($link->url,$file);

    print $file," : "$link->url,"\n";

    print $doc $link->url." ".$file."\n";

    $count+=1;
  }
  close $doc;
  exit;
  }

 images();
Rumpus answered 15/12, 2012 at 16:37 Comment(0)
R
0

No not here not anywhere on the web. The Facemash source code has never been released to the public. The only one, who might still have a copy is Mark Zuckerberg himself.

Rimmer answered 3/10, 2010 at 0:9 Comment(0)
A
0

here is a clone of facemash available http://www.facemash.99k.org

Affiche answered 23/3, 2012 at 19:23 Comment(0)
O
0

I've recreated it as well, but in a WordPress plugin

http://pofornot.com/

http://codecanyon.net/item/pics-mash-image-rating-tool/3256459?ref=mikemayhem3030

Optimal answered 20/12, 2012 at 22:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.