How can I calculate the PageRank for my small network?

I have two records in my Mysql database

table1 has all the web pages on my network

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

      

table2 has two fields which are the link source page and link landing page

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

      

How to calculate page rank for my network

I found this article here it explains the PageRank algorithm but it is very difficult to write my formula in PHP +, I am not good at math

thank

update:

I have almost 5000 pages on my network

+2


source to share


2 answers


HI again

I think I figured out how to do this, but I'm not sure

I'll take care of you and you judge if my calculation is correct or not

first I added a new column to the "pages" table called "outbound links", it has the count of outbound links from that page

and I added two more columns "pagerank" and "pagerank2"

and another column named "i" that counts the number of iterations

now let's move on to programming

     $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'");
           }
         }
      }

      



Note:

before you start, make sure the page of one page (any page) is set to 1 and the rest of the pages are set to 0

why two columns are pageranks?

I did this because I think we have to split each iteration into an accurate calculation so that our script alternates between these two columns, each iteration will process one of the page rank columns and store the new results into another column of the column

the previous code will loop many times to get accurate results, for example 50 times every time we get close to real pages for our pages

my question is if the sum of all pageranks on my network should be 1! if so, how does Google give each page a 10 rating ?!

any ideas?

thank

+1


source


Why do you need PageRank if it's your own network? Why not just calculate the total number of links from unique pages to a specific page and use that number as your page rank?



0


source







All Articles