The first week: PageRank learning experience--java Programming Realization __ios

Source: Internet
Author: User
Tags getmessage

Recently reviewed Hadoop found a lot of notes before, posted out very everyone share under.


a brief introduction to Google matrix and page Rank

Page rank, part of Google's ranking algorithm, is a way for Google to identify the level/importance of Web pages, and is the standard that Google uses to measure a site's quality. After blending all the other factors, such as the title tag and the keywords logo, Google adjusts the results by PageRank to make those more "grade/importance" pages more ranked in search results, improving the relevance and quality of search results. Its level from 0 to 10, 10 for full marks. The higher the PR value means the more important the Web page is.
Google's PageRank measure the value of a site based on the number and quality of external links and internal links.
[above quoted from: Baidu Encyclopedia, see http://baike.baidu.com/view/1518.htm in detail, do not introduce more]


Matrix Concept related

I believe many people forget about the "linear algebra" of the university; in the Google matrix solution process we have to use a few basic concepts: eigenvector, matrix addition, matrix multiplication.

A matrix is a two-dimensional array. A matrix of n rows m columns can be multiplied by a matrix of m rows p columns, the resulting result is a matrix of n rows p columns, where the number of the J column in line I is equal to the sum of all M products multiplied by the M number on line I of the previous matrix and the M number on the first J column of the Last matrix. For example, the following formula represents a matrix of 2 rows of 2 columns multiplied by 2 rows of 3 columns, and the result is a 2 row 3 column matrix

If you forget about it (landlord is also), it is recommended to spend two or three hours to review. Recommendation: Http://wenku.baidu.com/view/3d8e80373968011ca30091c0 from page 14th (determinant) start to recall.

(digression: Everyone is cursing the irrationality of college-oriented education, but here we can find: the wrong is the system itself rather than knowledge. For the acquisition of knowledge: I have learned to forget and I have not learned is a qualitative difference---welcome to make bricks)

If you still haven't figured out the eigenvector, can actually skim first, as is an n row 1 column of the matrix (haha originally is), we want through this matrix to continue to carry out Q (n) =g*q (n-1) (G is Pangrank matrix, Q is eigenvector) operation, until Q (n) =q ( n-1), q (n) is the value of PR.

Reference information: http://www.cnblogs.com/itTeacher/archive/2013/06/08/3126914.html


Implementing PageRank with Java programming

Package com.hadoop;


        public class Getpagerank {//A is a damping factor, Google takes a equals 0.85 private static float alpha = 0.85f;

                        public static void Main (string[] args) {try {//Transfer matrix  Float[][] S = {0, 0, 0, 0}, {0.3333333f, 0, 0, 1}, {0.3333333f, 0.5f, 0,


                        0}, {0.3333333f, 0.5f, 1, 0}};

                                        Initial eigenvector float[][] U = {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1},


                        {1, 1, 1, 1}}; float[][] F1 = Multigenematrix (alpha, S);/as float[][] F2 = Multigenematrix ((1-alpha)/s[1). length, U);//(1-A)/n*u//Get pagerank float[][] G = Addmatrix (f1, F2);


                        /as+ (1-A)/n*u//Print matrix content Printcontentofmatrix (G);Eigenvector float[] Pr_cur = {1f, 1f, 1f, 1f};//result:0.15000004 1.492991

                        0.82702124 1.5299894 int i = 0;

                        Ask PageRank value Q (n) =g*q (n-1) until Q (n) =q (n-1), q (n) is the value of PR.

                                while (true) {float[] Pr_next = Multimatrixvector (G, pr_cur); if (Comparematrix (Pr_cur, Pr_next)) {System.out.println ("Total calculated: + i +")

                                        Times "); System.out.println (Pr_next[0] + "--" + pr_next[1] + "--" + Pr_nex

                                        T[2] + "--" + pr_next[3]);

                                Break

                                        else {i++;

                                Pr_cur = Pr_next;

                }        The catch (Exception e) {System.out.println (E.getmessage ());

                }//matrix multiplies with vectors public static float[] Multimatrixvector (float[][] m, float[] v) {

                float[] RV = null;


                        try {RV = new float[v.length]; 

                                        for (int vl = 0; VL < V.length, vl++) {for (int row = 0; row < m.length; row++) {

                                        float one = 0; for (int col = 0; col < m[1].length col++) {one + = M[row][col] * v[c

                                        OL];

                                } Rv[row] = one; The catch (Exception e) {System.out.println (e.getmes

               Sage ()); return RV; }//Two matrix addition public static float[][] Addmatrix (float[][] F1, float[][] f2) {float[][]


                result = NULL;


                        try {result = new Float[f1.length][f1[1].length]; for (int row = 0; row < f1.length. row++) {for (int col = 0; col < f1[1].length; c

                                ol++) {Result[row][col] = F1[row][col] + F2[row][col];  The catch (Exception e) {} return

        Result  }//matrix multiplication factor public static float[][] Multigenematrix (float F, float[][] FM) {float[][]

                result = NULL;


                        try {result = new Float[fm.length][fm[1].length];

              for (int row = 0; row < fm.length; row++) {                  for (int col = 0; col < fm[1].length; col++) {Result[row][c

                                OL] = Fm[row][col] * F;

        The catch (Exception e) {} return result;

                        }//Print matrix content public static void Printcontentofmatrix (float[][] f) {try {

                        System.out.println ("--------------get the Google matrix as follows---------------"); for (int row = 0; row < f.length. row++) {for (int col = 0; col < F[1].length; col

                                + +) {System.out.print (F[row][col] + "");

                        } System.out.println (); } System.out. println ("---------------------------------

        -------------");        catch (Exception e) {System.out.println (E.getmessage ());

                }//Compare two eigenvector public static Boolean Comparematrix (float[] Now, float[] next) { try {for (int i = 0; i < next.length; i++) {if (Next-

                                Now > 0.0000001) {return false; The catch (Exception e) {System.out.println (e.getmes

                Sage ());

        return true; }


}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.