DAY 28
0

# PageRank

### 搜尋引擎最佳化(Search Engine Optimization,SEO)

「針對搜尋引擎作最佳化的處理」，是指為了要讓網站更容易被搜尋引擎接受。搜尋引擎會將網站彼此間的內容做一些相關性的資料比對，然後再由瀏覽器將這些內容以最快速且接近最完整的方式，呈現給搜尋者。

# 用Python實現PageRank

#how we update the PageRank
def PageRank_one_iter(graph, d):
node_list = graph.nodes
for node in node_list:
node.update_pagerank(d, len(graph.nodes))

#Calculate new PageRank
def update_pagerank(self, d, n):
in_neighbors = self.parents
pagerank_sum = sum((node.pagerank / len(node.children)) for node in in_neighbors)
random_walk = d / n
self.pagerank = random_walk + (1-d) * pagerank_sum

# 用JavaScript實現PageRank

Matrix.prototype.row_stochastic = function(damping_factor) {

var row_length = this.elements[0].length;
var d = (1 - damping_factor) / row_length;

var row_total = [];

for (var x = 0; x < row_length; x++) {
row_total.push(0);
for (y = 0; y < row_length; y++) {
row_total[x] += this.elements[x][y];
}
}

var a1 = this.elements.clone();

for (var x = 0; x < row_length; x++) {
for (var y = 0; y < row_length; y++) {
if (row_total[x] > 0) {
a1[x][y] = a1[x][y]/row_total[x] + d;
}
else {
a1[x][y] = (1/row_length) + d;
}
}
}

return \$M(a1);

}