页面排名MATLAB

时间:2013-11-28 14:45:00

标签: matlab numerical-methods

尝试修复我的代码页面排名。不确定为什么功率方法和反斜杠会出现不同的答案,哪些是错误的以及如何解决它。

    p=rand(length(M),1);
    pnorm=norm(p,1);
    p=p/pnorm;
    n=length(M);

    d=0;
    e=ones(n,1);
    a=1/n;
    Z=a*(e*e');
    Mtilda=d*M+(1-d)*Z;


    for k=1:n
        tic;
        prev_p = p;
        z = Mtilda*p;
        p = z/norm(z,2);
        dl_p = norm(p-prev_p, 2);
        t(k)=toc;
        str=sprintf('for d=%g , iteration %d: time=%11.4g',d,k,t(k));
        disp(str);
    if dl_p < 1e-6; break; end
    end


    ReportPageRank(p,U,0.005)
    d=1;
    p2 =(eye(n)-d*M)\((((1-d)/n)*e));

1 个答案:

答案 0 :(得分:3)

你已经弄明白了,但是如果有人对实施感兴趣,我会发布我的作品。

M = ...
[  0.09091   0.00000   0.00000   0.50000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   1.00000   0.50000   0.33333   0.50000   0.50000   0.50000   0.50000   0.00000   0.00000;
   0.09091   1.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   0.00000   0.00000   0.33333   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   0.00000   0.00000   0.00000   0.50000   0.50000   0.50000   0.50000   1.00000   1.00000;
   0.09091   0.00000   0.00000   0.00000   0.33333   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000;
   0.09091   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000   0.00000];
N = length(M);
PR = (1/N)*ones(length(M),1);   %define PageRank vector for t = 0
d = 0.85;                       %define damping rate
iter = 1;
delta_PR = Inf;                 %set initial error to infinity
while delta_PR > 1e-6           %iterate until error is less than 1e-6
    tic;

    prev_PR = PR;               %save previous PageRank vector (t-1)
    PR = d*M*PR + ((1-d)/N)*ones(N,1);  %calculate new PageRank (t)

    delta_PR = norm(PR-prev_PR);%calculate new error
    t(iter)=toc;
    str=sprintf('for d=%g , iteration %d: time=%11.4g',delta_PR,iter,t(iter));
    disp(str);
    iter = iter + 1;
end

powerRank = pinv((eye(length(M)) - d*M))*(((1-d)/N)*ones(length(M),1));

PR = powerRank =

    0.0328
    0.3844
    0.3429
    0.0391
    0.0809
    0.0391
    0.0162
    0.0162
    0.0162
    0.0162
    0.0162