function [ affinity ] = CalcPHsAffinityByKatzBeta( data, beta, infinity, firstPH)
    % sigal 29.10.13 
    % based on CalcAffinityByKatzBeta_Sparse

    %sigal
    extraLen=0;
    infinity = infinity+extraLen;

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

    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 - return only PHs
    affinity = affinity(firstPH:end,firstPH: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

