Concepts / Link Analysis and Network Structure

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.

  • Programming

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

  1. Invoke sprank.py and provide the number of iterations to perform.
  2. The program makes one complete pass through the pages in the database.
  3. It recalculates page scores using the results from the previous iteration.
  4. It reports the iteration number and the average change in PageRank score per page.
  5. It repeats the process for the requested number of iterations.
refine scorescontinue until stableIteration 1Average change: 0.547Iteration 2Average change: 0.227Later iterationsVery small average change
How do PageRank scores change across successive iterations, and how can you tell when they have stabilized?

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.

links tolinks tolinks tolinks toPage APage BPage CPage D
How do links between pages cause PageRank importance to flow through the network?

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.

higher score thanhigher score thanPage 42.135Page 20.659Page 50.659Page 10.559
How do the final PageRank values correspond to the relative importance of pages in the link network?
Output informationWhat it tells you
Page IDWhich page the record describes
PageRank scoreThe page's relative importance in the network
Outlink countHow many outgoing links the page has
URLThe page location stored in the record
Version numberThe 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.

reuse scores as starting valuescontinue iteratingFirst runInitial refined scoresSecond runFurther refinementStable rankingIf further changes arenegligible
What changes between one run of sprank.py and the next, and why can the rankings become more reliable?

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.

add pages and linksread network structurestore scoresspider.pyCrawl pagesPage databasePages and linkssprank.pyIterate scoresPageRank outputUpdated rankings
How does crawled page and link data move into the PageRank calculation and produce updated rankings?

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.

restart calculationpreserve network structurerun againRanked databasePages, links, scoresspreset.pyClear scoresInitial statePages and links retainedsprank.pyRecalculate scores
What signs show that PageRank has stabilized, and when should the calculation be reset or run again after the network changes?
  • 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

MEDIUM

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.
EASY

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

  1. sprank.py iteratively transforms stored pages and links into PageRank scores.
  2. The average change reported after each iteration shows whether the scores are still moving substantially.
  3. A declining average change indicates convergence; very small changes indicate stable, reliable rankings.
  4. Scores are relative to the pages in the same network, and output can include page IDs, scores, outlink counts, URLs, and version information.
  5. 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.