OCTAVE
Herramientas de cómputo - Octave
View more presentations from Jorge Sepúlveda
% 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
function [M]=GenerarM(size)
M=sparse(size,size);
for i=1:size
for j=1:size
if (i!=j)
if (rand(1)>=0.75)
M(i,j)=1;
endif
endif
endfor
endfor
MuestraM=full(M)
for j=1:size
suma=0;
for i=1:size
suma=suma+M(i,j);
endfor
for i=1:size
M(i,j)=M(i,j)/suma;
endfor
endfor
M=full(M);
endfunction
v=rank(GenerarM(15), 0.80, 0.001)
bar(v,'facecolor',"green")
title('Page Rank de las Paginas','Fontsize',48);
ylim([0,1])
xlim([0,16])
xlabel('NUMERO DE PAGINA','Fontsize',32)
ylabel('PAGE RANK','Fontsize',32)
print -djpg "grafica.jpg"