function [ affinity ] = CalcAffinityByKatzBeta_Sparse( data, beta, infinity, num_attr_nodes )

%sigal
if num_attr_nodes>0
    extraLen=0;
else
    extraLen=0;
end
infinity = infinity+extraLen;

%data(eye(size(data,1)) == 1) = 1;

start_beta = beta;
d_next = data;
affinity = sparse(d_next .* beta);

if num_attr_nodes>0
    d_next(1:num_attr_nodes,:)=0;
    d_next(:,1:num_attr_nodes)=0;
end

d_next = sparse(d_next);
for n = 2 : infinity
   
    d_next = sparse(d_next * data);
    
    beta = beta * start_beta;
    
    affinity = sparse(affinity + (d_next .* beta));
    
end

%sigal 29.10.13 - normolize by diagonal min
v = diag(affinity);
max_val = min(v);
%max_val = max(max(affinity));

affinity = affinity ./ max_val;

for i = 1 : size(affinity,1)
    affinity(i,i) = 1;
end
%sigal 29.10.13 - end 

end %function

