Link Analysis and Network Structure
PageRank is computed by running sprank.py, which iteratively calculates importance scores based on the link structure in your database.
From Links to Scores
PageRank turns a database of web pages and their links into numerical importance scores. The calculation is performed by sprank.py. Rather than producing final rankings in one immediate pass, the program repeatedly examines the link structure and refines each page's score using the scores from the previous iteration.
A PageRank score is relative to the other pages in the same network. A higher score means that the page is considered more important according to the link structure stored in the database.
The Iteration Cycle
- Invoke sprank.py and provide the number of iterations to perform.
- The program makes one complete pass through the pages in the database.
- It recalculates page scores using the results from the previous iteration.
- It reports the iteration number and the average change in PageRank score per page.
- It repeats the process for the requested number of iterations.
The average change is the main progress signal. In the source example, a calculation over five pages reports an average change of 0.547 after the first iteration and 0.227 after the second. The decrease means that the scores changed less during the second pass. A continuing decrease toward a very small value indicates that the rankings are stabilizing.
Importance Flow Through Links
The link network creates a feedback loop. A page can gain importance when it receives links from pages that themselves have high scores. During each iteration, this information propagates through the network, so the algorithm repeatedly adjusts the scores instead of relying only on the number of incoming links.
Reading the Output
Comparing PageRank Scores
Interpret a set of PageRank scores produced for pages in one network.
Find the largest score: Page 4 has a score of 2.135, the highest value in the listed results.
Compare the middle values: Pages 2 and 5 are tied at 0.659.
Compare the lower value: Page 1 has a score of 0.559, slightly below the scores for pages 2 and 5.
Interpret the ordering: Within this network, Page 4 is ranked as more important than the other listed pages according to the stored link structure.
The values are relative rankings for pages in the same network, not universal importance values that can be compared directly with scores from a different network.
| Output information | What it tells you |
|---|---|
| Page ID | Which page the record describes |
| PageRank score | The page's relative importance in the network |
| Outlink count | How many outgoing links the page has |
| URL | The page location stored in the record |
| Version number | The record's version information, shown in the detailed database record |
PageRank output can appear as simple score tuples or as detailed database records.
Repeated Runs and Refinement
A single run does not have to be the end of the process. You can run sprank.py multiple times on the same database. A later run starts with the scores produced by the earlier run and iterates again, allowing the rankings to converge further when additional refinement is needed.
A second run can refine convergence, but it does not replace the need to inspect the average change. The metric tells you whether additional passes are still making meaningful adjustments.
Crawling Before Ranking
PageRank can be combined with crawling as an ongoing workflow. spider.py crawls new pages and adds them to the database. sprank.py can then recalculate the scores using the expanded collection of pages and links, allowing the rankings to reflect the updated network.
Resetting the Calculation
Use spreset.py when you need to restart PageRank from its initial state without crawling all the pages again. The reset clears the stored PageRank values but preserves the page records and the links between them. You can then run sprank.py from the beginning on the same network structure.
- Continue or repeat ranking when the average change is still large and the scores are still shifting noticeably.
- Treat very small average changes as evidence that the rankings have stabilized.
- Run sprank.py again after spider.py adds pages or links.
- Use spreset.py before a fresh calculation when you want to test different parameters, verify results, or remove old score values while keeping the crawled network.
Common Diagnostic Errors
Treating the first iteration as the final ranking
Early iterations make significant corrections to the initial estimates.
Fix:
Compare the average change across iterations and continue until the changes become very small.Reading a score as an absolute measure of importance
PageRank scores are relative to the other pages in the same network.
Fix:
Use the scores to compare pages within the database that produced them.Ignoring the link structure behind the score
PageRank is calculated from the link structure, and detailed records include outlink counts to provide topology context.
Fix:
Inspect the page's score together with its link-related metadata.Assuming a crawl automatically updates existing rankings
New pages and links change the network being ranked.
Fix:
Run sprank.py again after the crawl.Resetting the database when only the scores need restarting
spreset.py is designed to clear PageRank values while preserving page records and link structure.
Fix:
Use spreset.py when you need a fresh calculation on the same network.
Check Your Interpretation
A two-iteration run reports an average change of 0.547 after the first iteration and 0.227 after the second. Explain what this decrease suggests, whether the rankings should automatically be called fully converged, and what evidence you would inspect before deciding to stop.
Hints
- The average change measures how much scores shift per page during an iteration.
- A decrease indicates stabilization, but convergence is associated with changes becoming very small.
- Consider whether later iterations would still be useful.
Your crawler adds new pages and links to the database. Describe the next program you would run, what it should recalculate, and when spreset.py would be appropriate instead.
Hints
- New links change the network being ranked.
- A fresh ranking run should account for the expanded network.
- A reset clears scores but keeps pages and links.
Stable Rankings in Practice
- sprank.py iteratively transforms stored pages and links into PageRank scores.
- The average change reported after each iteration shows whether the scores are still moving substantially.
- A declining average change indicates convergence; very small changes indicate stable, reliable rankings.
- Scores are relative to the pages in the same network, and output can include page IDs, scores, outlink counts, URLs, and version information.
- Run PageRank again after crawling changes the network, and use spreset.py to clear old scores without deleting the stored pages and links.
Key Takeaways
- PageRank uses repeated passes over a database's link structure to calculate relative page importance.
- The average change per iteration is the key signal for recognizing convergence.
- Repeated runs can refine scores, while new crawls require rankings to be recalculated.
- spreset.py restarts the score calculation without removing the page and link network.