ivan@152: function colors = dico_color(dico, mu) ivan@152: % DICO_COLOR cluster a dictionary in pairs of high correlation atoms. ivan@152: % Called by dico_decorr. ivan@152: % ivan@152: % Parameters: ivan@152: % -dico: the dictionary ivan@152: % -mu: the correlation threshold ivan@152: % ivan@152: % Result: ivan@152: % -colors: a vector of indices. Two atoms with the same color have a ivan@152: % correlation greater than mu ivan@152: ivan@152: numAtoms = length(dico); ivan@152: colors = zeros(numAtoms, 1); ivan@152: ivan@152: % compute the correlations ivan@152: G = abs(dico'*dico); ivan@152: G = G-eye(size(G)); ivan@152: ivan@152: % iterate on the correlations higher than mu ivan@152: c = 1; ivan@152: maxCorr = max(max(G)); ivan@152: while maxCorr > mu ivan@152: % find the highest correlated pair ivan@152: x = find(max(G)==maxCorr, 1); ivan@152: y = find(G(x,:)==maxCorr, 1); ivan@152: ivan@152: % color them ivan@152: colors(x) = c; ivan@152: colors(y) = c; ivan@152: c = c+1; ivan@152: ivan@152: % make sure these atoms never get selected again ivan@152: G(x,:) = 0; ivan@152: G(:,x) = 0; ivan@152: G(y,:) = 0; ivan@152: G(:,y) = 0; ivan@152: ivan@152: % find the next correlation ivan@152: maxCorr = max(max(G)); ivan@152: end ivan@152: ivan@152: % complete the coloring with singletons ivan@152: index = find(colors==0); ivan@152: colors(index) = c:c+length(index)-1; ivan@152: end