vote from an important page is worth more.flowchart TD
Y((y)) -->|y/2| Y((y));
Y -->|y/2| A((a));
A -->|a/2| Y;
A -->|a/2| M((m));
M -->|m| A;
N web pages on the Internet.1/N.…
spider trap problema and b.graph LR
A((a)) --> B((b));
B -->A;
dead end problema and b.graph LR
A((a)) --> B((b));
flowchart LR
subgraph ORIGINAL
direction TB
Y1((y)) --> Y1((y));
Y1 --> A1((a));
A1 --> Y1;
A1 --> M1((m));
end
subgraph RANDOM_TELEPORT
direction TB
Y2((y)) --> Y2((y));
Y2 --> A2((a));
A2 --> Y2;
A2 --> M2((m));
M2 .-> STOP[ ]
end
ORIGINAL --> RANDOM_TELEPORT
style STOP fill:#FFFFFF00, stroke:#FFFFFF00;
to
\[\left[ \begin{array}{ccc} 1/2 & 1/2 & 0 \\ 1/2 & 0 & 1 \\ \textbf{1/3} & \textbf{1/3} & \textbf{1/3} \end{array} \right]\]where $\left[ \frac{1 - \beta}{N}\right]_{N}$ is a vector with all $N$ entries have the same value $\frac{1-\beta}{N}$.
This hands-on should be done on a notebook
1
2
3
4
5
y y
y a
a y
a m
m a
1
2
graph_data = sc.textFile("small_graph.dat")
graph_data.take(5)
1
2
3
4
5
6
links = graph_data.map(lambda line: (line.split(" ")[0], line.split(" ")[1]))
print(links.take(10))
links = links.groupByKey()
print(links.take(10))
links = links.mapValues(list)
print(links.take(10))
1
2
3
N = links.count()
ranks = links.map(lambda line: (line[0], 1/N))
ranks.take(3)
1
2
3
4
5
6
7
8
def calculateVotes(t):
res = []
for item in t[1][1]:
count = len(t[1][1])
res.append((item, t[1][0] / count))
return res
###############################
calculateVotes(('y', (0.3333333333333333, ['y', 'a'])))
1
2
votes = ranks.join(links)
votes.take(10)
1
2
votes = votes.flatMap(calculateVotes)
print(votes.take(10))
1
2
ranks = votes.reduceByKey(lambda x,y: x + y)
ranks.take(10)
1
2
3
4
5
%%time
for i in range(10):
votes = ranks.join(links).flatMap(calculateVotes)
ranks = votes.reduceByKey(lambda x,y: x + y)
print(ranks.take(3))
1
2
3
4
5
6
7
8
9
10
%%time
sum = 1
while sum > 0.01:
old_ranks = ranks
votes = ranks.join(links).flatMap(calculateVotes)
ranks = votes.reduceByKey(lambda x,y: x + y)
errors = old_ranks.join(ranks).mapValues(lambda v: abs(v[0] - v[1]))
sum = errors.values().sum()
print(sum)
print(ranks.take(3))
The link to the notebook can be found at [PageRank Colab]https://drive.google.com/file/d/15FcDnUk1b7PL1NZkV1r7WySy_MwqRzQP/view?usp=sharing)
authorities).hub).n pages on the Web flowchart LR
A((A)) --> B((B))
A --> C((C))
A ---> D((D))
B ---> A
B ---> D
C --> E((E))
D --> B
D --> C
hubbiness of a page is proportional to the sum of the authority of its successor. authority), then the value of that hub (hubbiness) will be high.authority of a page is proportional to the sum of the hubbiness of its predecessor. hubbiness), then that page must be of high quality (high authority).
1
2
3
4
5
6
7
8
9
%%file small_web.dat
A B
A D
A C
B A
B D
C E
D C
D B
The link to the notebook can be found at Sequential HITS Colab
The link to the notebook can be found at HITS Colab