有人知道Mark Zuckerberg在facemash网站上实施的facemash算法吗? http://www.thecrimson.com/article/2003/11/19/facemash-creator-survives-ad-board-the/
最好是PHP&的MySQL。
答案 0 :(得分:28)
更新:
正如我在评论中所说,我已将这个算法添加到我的新网站。起初它似乎工作得很好。但经过一些奇怪的输入后,一些奇怪的结果开始形成。
调试时我弄清楚我做错了什么。当获得2个节点之间的“直接关系”(在间接关系中使用)的得分时,我将得分加在一起。这是错误的,直接关系的得分应该用-1到+1表示,其中:
-1 = lost everything
+1 = won everything
因此,如果A赢了8次B,B赢了2次A,那么得分应该是:
(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跳。
答案 1 :(得分:15)
我不知道实际网站实际使用了什么算法,但是他们在电影中的窗口上写的是基于Elo rating system,它起源于国际象棋世界,现在也是用于许多其他游戏。
答案 2 :(得分:5)
我重新创建它以及检查出来。 不确定php,但C#类是
我在我的
上使用过它按键代码是
$(document).keydown(function(event) {
if (event.keyCode == 37) {
//Voted Face 1
Rate("face1", false);
}
if(event.keyCode == 39) {
//Voted Face 2
Rate("face2", false);
}
});
答案 3 :(得分: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
?>
答案 4 :(得分:1)
`我已经在谷歌搜索中设计了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();
答案 5 :(得分:0)
不,这里不在网上任何地方。 Facemash源代码从未向公众发布。唯一一个可能仍然有副本的人是Mark Zuckerberg他自己。
答案 6 :(得分:0)
这里是facemash的克隆http://www.facemash.99k.org
答案 7 :(得分:0)
我也重新创建了它,但是在WordPress插件中
http://codecanyon.net/item/pics-mash-image-rating-tool/3256459?ref=mikemayhem3030