function [attAffinity] = CalcAttributesAffinity_S3(data, attData, last_known_node, addMissingAtt, threshold)
    n = size(attData,1);
    numAtt = size(attData,2);
    
    if addMissingAtt> 0 && last_known_node < n
        attData = AddMissingNodesAttrFromNeighborsNeighbors(data, attData, last_known_node, addMissingAtt);
    end
    
    count = sum(attData,2);
    nnz_n = nnz(count);
    LogMsg(sprintf('attAffinity count  (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n, 100*nnz_n/n));
%    fprintf('calculating attribtes affinity matrix - common start\n');
    common = sparse(attData*attData');
    [r,c] = find(common);
    nnz_n=size(r,1);%x=nnz(attAffinity);
    perc_nnz = nnz_n/(n*n);
    LogMsg(sprintf('attAffinity common (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*perc_nnz));
    % Sigal 22.3.13 - TODO use sparse if x < 40%
    if perc_nnz>0.4
        LogMsg(sprintf('*** WARNING: attAffinity - use sparse for more than 40%% full matrix (n=%d,p=%.3f)',n,perc_nnz));
    end
    
%     attAffinity = sparse(n,n);
%     for i=1:nnz_n
%         val = common(r(i),c(i));
%         total = count(r(i))+count(c(i))-val;
% %         if (c(i)<31 && r(i)<31) 
% %             fprintf('(i,j)=(%d,%d): common=%f, total=%f\n',full(r(i))-1,full(c(i))-1,full(val),full(total));
% %         end
%         if total > 0 && val/total > threshold
%            attAffinity(r(i),c(i)) = val/total;
%         end
%     end
% 
%     nnz_n = nnz(attAffinity);
%     LogMsg(sprintf('attAffinity totalM (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
    
    attAffinity = AttributesSimilarity(common,count,threshold);
    nnz_n = nnz(attAffinity);
    LogMsg(sprintf('attAffinity totalC (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
    
%     diff = attAffinityC-attAffinity;
%     nnz_n = nnz(diff);
%     LogMsg(sprintf('attAffinity diff  (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
    
end %function
