Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

page rank example

#!/usr/bin/perl

$damp = 0.85;
$norm = 1 - $damp;

$a = 0;
$b = 0;
$c = 0;
$d = 0;
$i = 40; # loop 40 times

# forward links
# a -> b, c	- 2 outgoing links
# b -> c	- 1 outgoing link
# c -> a	- 1 outgoing link
# d -> a	- 1 outgoing link

# i.e. "backward" links (what's pointing to me?)
# a <= c
# b <= a
# c <= a, b, d
# d - nothing
while ($i--) {
    printf(
    	"a: %.5f b: %.5f c: %.5f d: %.5f
",
    	$a, $b, $c, $d
    );
	$a = $norm + $damp * $c;
	$b = $norm + $damp * ($a/2);
	$c = $norm + $damp * ($a/2 + $b + $d);
	$d = $norm;
}
printf("Average pagerank = %.4f
", ($a + $b + $c + $d) / 4);
Source by ianrogers.uk #
 
PREVIOUS NEXT
Tagged: #page #rank
ADD COMMENT
Topic
Name
7+4 =