Question

There's an implementation of Googles' PageRank on wikipedia:

% Parameter M adjacency matrix where M_i,j represents the link from 'j' to 'i', such that for all 'j' sum(i, M_i,j) = 1
% Parameter d damping factor
% Parameter v_quadratic_error quadratic error for v
% Return v, a vector of ranks such that v_i is the i-th rank from [0, 1]

function [v] = rank(M, d, v_quadratic_error)

N = size(M, 2); % N is equal to half the size of M
v = rand(N, 1);
v = v ./ norm(v, 2);
last_v = ones(N, 1) * inf;
M_hat = (d .* M) + (((1 - d) / N) .* ones(N, N));

while(norm(v - last_v, 2) > v_quadratic_error)
        last_v = v;
        v = M_hat * v;
        v = v ./ norm(v, 2);
end

endfunction

I can' figure out what's quadratic_error for. It's not described on wikipedia nor in the article's algorithm specification.

Was it helpful?

Solution

It looks like it is a convergence test. The while loop ends when the L2 difference between v and last_v does not exceed the value of v_quadratic_error.

Here's a bit more explanation. First, note that M_hat is a matrix and v is a vector. The while loop replaces v with the product M_hat * v (normalized to be a unit vector). The loop ends when the change in v due to one iteration is small enough. That's what "convergence" means in this context.

This appears to be the standard power iteration loop for finding the eigenvector corresponding to the dominant eigenvalue of a matrix (in this case of M_hat). Without knowing more about the overall algorithm (which I'm not going to research), I can't say why this calculation is useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top