[box type=”note” align=”” class=”” width=””]The article given below is a book excerpt from Java Data Analysis written by John R. Hubbard.

Data analysis is a process of inspecting, cleansing, transforming, and modeling data with the aim of discovering useful information. Java is one of the most popular languages to perform your data analysis tasks. This book will help you learn the tools and techniques in Java to conduct data analysis without any hassle. [/box]

This post aims to help you learn how to analyse big data using Google’s PageRank algorithm.

The term big data generally refers to algorithms for the storage, retrieval, and analysis of massive datasets that are too large to be managed by a single file server. Commercially, these algorithms were pioneered by Google, Google’s PageRank being one of them is considered in this article.

## Google PageRank algorithm

Within a few years of the birth of the web in 1990, there were over a dozen search engines that users could use to search for information. Shortly after it was introduced in 1995, AltaVista became the most popular among them. These search engines would categorize web pages according to the topics that the pages themselves specified.

But the problem with these early search engines was that unscrupulous web page writers used deceptive techniques to attract traffic to their pages. For example, a local rug-cleaning service might list “pizza” as a topic in their web page header, just to attract people looking to order a pizza for dinner. These and other tricks rendered early search engines nearly useless.

To overcome the problem, various page ranking systems were attempted. The objective was to rank a page based upon its popularity among users who really did want to view its contents. One way to estimate that is to count how many other pages have a link to that page. For example, there might be 100,000 links to https://en.wikipedia.org/wiki/Renaissance, but only 100 to https://en.wikipedia.org/wiki/Ernest_Renan, so the former would be given a much higher rank than the latter.

But simply counting the links to a page will not work either. For example, the rug-cleaning service could simply create 100 bogus web pages, each containing a link to the page they want users to view.

In 1996, Larry Page and Sergey Brin, while students at Stanford University, invented their PageRank algorithm. It simulates the web itself, represented by a very large directed graph, in which each web page is represented by a node in the graph, and each page link is represented by a directed edge in the graph.

The directed graph shown in the figure below could represent a very small network with the same properties:

This has four nodes, representing four web pages,** A**, **B**, **C**, and **D**. The arrows connecting them represent page links. So, for example, page **A** has a link to each of the other three pages, but page **B** has a link only to **A**.

To analyze this tiny network, we first identify its **transition matrix**, *M *:

This square has 16 entries, *m**ij*, for 1 ≤* i* ≤ 4 and 1 ≤* j *≤ 4. If we assume that a web crawler always picks a link at random to move from one page to another, then *m**ij*, equals the probability that it will move to node *i *from node* j*, (numbering the nodes A, B, C, and D as 1, 2, 3, and 4). So *m**12* = 1 means that if it’s at node B, there’s a 100% chance that it will move next to A. Similarly, *m**13* = *m**43* = ½ means that if it’s at node C, there’s a 50% chance of it moving to A and a 50% chance of it moving to D.

Suppose a web crawler picks one of those four pages at random, and then moves to another page, once a minute, picking each link at random. After several hours, what percentage of the time will it have spent at each of the four pages?

Here is a similar question. Suppose there are 1,000 web crawlers who obey that transition matrix as we’ve just described, and that 250 of them start at each of the four pages. After several hours, how many will be on each of the four pages?

This process is called a **Markov chain**. It is a mathematical model that has many applications in physics, chemistry, computer science, queueing theory, economics, and even finance.

The diagram in the above figure is called the state diagram for the process, and the nodes of the graph are called the states of the process. Once the state diagram is given, the meaning of the nodes (web pages, in this case) becomes irrelevant. Only the structure of the diagram defines the transition matrix *M*, and from that we can answer the question. A more general Markov chain would also specify transition probabilities between the nodes, instead of assuming that all transition choices are made at random. In that case, those transition probabilities become the non-zero entries of the *M*.

A Markov chain is called irreducible if it is possible to get to any state from any other state. According to the mathematical theory of Markov chains, if the chain is irreducible, then we can compute the answer to the preceding question using the transition matrix. What we want is the steady state solution; that is, a distribution of crawlers that doesn’t change. The crawlers themselves will change, but the number at each node will remain the same.

To calculate the steady state solution mathematically, we first have to realize how to apply the transition matrix *M*. The fact is that if **x** = (*x**1** , x**2** , x**3** , x**4* ) is the distribution of crawlers at one minute, and the next minute the distribution is **y** = (*y**1** , y**2 **, y**3** , y**4* ), then **y** = *M*x , using matrix multiplication.

So now, if **x **is the steady state solution for the Markov chain, then M**x** = **x**. This vector equation gives us four scalar equations in four unknowns:

One of these equations is redundant (linearly dependent). But we also know that *x**1** + x**2** + x**3** + x**4* = 1, since **x** is a probability vector. So, we’re back to four equations in four unknowns. The solution is:

The point of that example is to show that we can compute the steady state solution to a static Markov chain by solving an *n* × n matrix equation, where *n* is the number of states. By static here, we mean that the transition probabilities *m**ij* do not change. Of course, that does not mean that we can mathematically compute the web. In the first place, *n* > 30,000,000,000,000 nodes! And in the second place, the web is certainly not static. Nevertheless, this analysis does give some insight about the web; and it clearly influenced the thinking of Larry Page and Sergey Brin when they invented the PageRank algorithm.

The purpose of the PageRank algorithm is to rank the web pages according to some criteria that would resemble their importance, or at least their frequency of access. The original simple (pre-PageRank) idea was to count the number of links to each page and use something proportional to that count for the rank. Following that line of thought, we can imagine that, if **x** = (*x**1** , x**2** ,…, x**n* )T is the page rank for the web (that is, if *x**j* is the relative rank of page *j* and ∑*x**j* = 1), then *M***x** = **x**, at least approximately. Another way to put that is that repeated applications of *M* to **x** should nudge **x** closer and closer to that (unattainable) steady state.

That brings us (finally) to the PageRank formula:

where *ε* is a very small positive constant, **z** is the vector of all 1s, and *n* is the number of nodes. The vector expression on the right defines the transformation function *f *which replaces a page rank estimate **x** with an improved page rank estimate. Repeated applications of this function gradually converge to the unknown steady state.

Note that in the formula, *f* is a function of more than just **x**. There are really four inputs: **x**, *M*, *ε* , and *n*. Of course, **x** is being updated, so it changes with each iteration. But *M, ε* , and *n* change too. *M* is the transition matrix, *n* is the number of nodes, and *ε* is a coefficient that determines how much influence the **z**/*n* vector has. For example, if we set *ε* to 0.00005, then the formula becomes:

This is how Google’s PageRank algorithm can be utilized for the analysis of very large datasets.

*To learn how to implement this algorithm and various other machine learning algorithms for big data, data visualization, and more using Java, check out this book *** Java Data Analysis**.