代码之家  ›  专栏  ›  技术社区  ›  ahmed

我如何计算我的小型网络的PageRank?

  •  2
  • ahmed  · 技术社区  · 16 年前

             | table1: (pages)|
             |----------------|
             | id   | url     |
             |----------------|
    

    表2有两个字段,分别是链接的源页面和链接的目标页面

              |---------------------------|
              |table2(links)              |
              |---------------------------|
              |from_page_id   | to_page_id|
              |----------------------------
    

    here

    2 回复  |  直到 16 年前
        1
  •  1
  •   ahmed    16 年前

         $step="pg";
         for($i=0;$i<50;$i++){
             if($step=="pg2"){
                 $step="pg";
             }else{
                 $step="pg2";
             }
             $totalpages=5000;
             $sql1 = "select id from pages";
             $result1 = $DB->query($sql1);
             while($row1 = $DB->fetch_array($result1)){
                 $page_id = $row1["id"];
                 $sql = "select * from links where to_page_id = '$page_id'";
                 $result = $DB->query($sql);
                 $weights_of_links=0;//sum of pageranks/number of outgoing links
                 while($row = $DB->fetch_array($result)){
                       $from_page_id = $row["from_page_id"];
                       $row2 = get_record_select("pages","id = '$from_page_id'");
                       $outgoinglinks = $row2["outgoinglinks"];
                       if($step=="pg2"){
                               $from_page_id_pagerank = $row2["pagerank2"];
                       }else{
                               $from_page_id_pagerank = $row2["pagerank"];
                       }
    
                       $weights_of_links +=($from_page_id_pagerank/$outgoinglinks );
                 }
    
                //final step I tried to write the formula from wikipedia and the paper I have referred to
                $pagerank = .15/$totalpages + .85*($weights_of_links);
                //update the pagerank
               $ii = $i+1;
               if($step=="pg2"){
                     update_record("pages","id='$url_id'","pagerank='$pagerank',i='$ii'");
               }else{
                     update_record("pages","id='$url_id'","pagerank2='$pagerank',i='$ii'");
               }
             }
          }
    

    在开始之前,请确保将其中一个页面(任何页面)的pagerank设置为1,并将其他页面设置为0

    我的问题是,如果我的网络中所有寻呼机的总和应该等于1!

        2
  •  0
  •   Vladislav Rastrusny    16 年前

    推荐文章