【问题标题】:Facemash algorithm [closed]Facemash算法[关闭]
【发布时间】:2010-10-03 00:05:39
【问题描述】:

有人知道马克扎克伯格在他的 facemash 网站中实现的 facemash 算法吗? http://www.thecrimson.com/article/2003/11/19/facemash-creator-survives-ad-board-the/

最好在 PHP 和 MySQL 中。

【问题讨论】:

    标签: php algorithm facebook


    【解决方案1】:

    更新:

    正如我在 cmets 中所说,我已将此算法添加到我的新网站中。起初它似乎工作得很好。但是在一些奇怪的输入之后,一些奇怪的结果开始形成。

    在调试时,我发现我做错了什么。在获得 2 个节点之间的“直接关系”(也用于间接关系)的分数时,我将分数加在一起。这是错误的,直接关系的分数应该用-1到+1表示,其中:

    -1 = lost everything 
    +1 = won everything
    

    所以如果 A 赢了 B 8 次,B 赢了 A 2 次,那么比分应该是:

    (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
    

    我在最初的解释中也没有提到这一点,但这都是关于三角形的。因此,当我们查看间接分数时,您只需增加 1 跳即可。

    【讨论】:

    • 嗨彼得,我对分享这些信息有点怀疑。一方面,我认为这是属于人类的信息,因此我必须与你们分享。另一方面,确实有一些大公司正在寻找这样的东西来申请专利,以便用它来对付像我这样的人。通过将其保存在我自己的服务器上,我可以记录查看该页面的每个人,并在需要时可以在法庭上使用它。我很抱歉,但我一直这样。
    • 我猜你还是在这里添加了信息。谢谢。
    • 使婚礼脱机,现在在不同的项目中使用算法。它看起来仍然可以正常工作。
    • 有人用php实现过这个算法吗?
    【解决方案2】:

    我不知道现实世界的网站实际使用了什么算法,但他们在电影中的窗口上写的是基于Elo rating system,它起源于国际象棋世界,现在也用于许多其他游戏。

    【讨论】:

    【解决方案3】:

    我重新创建了它并查看它。 不确定 php 但 C# 类是

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

    我用过

    Facemash

    按键代码是

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

    【讨论】:

    • 上面写着“在社交网络中看到的”,但看起来确实不同。在电影中,它有一个厚实的红色标题和白色背景。
    • 你是如何实现左右键盘的使用的。你能分享它的代码吗?
    • 哇...您是如何让这么多人使用您的网站的? @卢克
    • 链接似乎是 404。您可以将代码发布到其他地方吗?
    【解决方案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
    
        ?>
    

    【讨论】:

      【解决方案5】:

      `我已经在 Perl 中设计了代码,全部来自谷歌搜索,它可以工作。

      在这里

      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();
      

      【讨论】:

        【解决方案6】:

        不,不在这里,也不在网络上的任何地方。 Facemash 源代码从未向公众发布。唯一可能还有一份副本的是Mark Zuckerberg本人。

        【讨论】:

          【解决方案7】:

          这是一个可用的facemash克隆http://www.facemash.99k.org

          【讨论】:

            【解决方案8】:

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2010-12-21
              • 2012-04-28
              • 2013-05-14
              • 2011-07-16
              • 2013-02-22
              • 2011-08-20
              • 2010-10-22
              相关资源
              最近更新 更多