pagerankpow.m

来自「有趣的可视的数值方法 出自网站http://www.mathworks.com」· M 代码 · 共 36 行

M
36
字号
function [x,cnt] = pagerankpow(G)% PAGERANKPOW  PageRank by power method with no matrix operations.% x = pagerankpow(G) is the PageRank of the graph G.% [x,cnt] = pagerankpow(G) also counts the number of iterations.% There are no matrix operations.  Only the link structure% of G is used with the power method.% Link structure[n,n] = size(G);for j = 1:n   L{j} = find(G(:,j));   c(j) = length(L{j});end% Power methodp = .85;delta = (1-p)/n;x = ones(n,1)/n;z = zeros(n,1);cnt = 0;while max(abs(x-z)) > .0001   z = x;   x = zeros(n,1);   for j = 1:n      if c(j) == 0         x = x + z(j)/n;      else         x(L{j}) = x(L{j}) + z(j)/c(j);      end   end   x = p*x + delta;   cnt = cnt+1;end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?