jordan@2: function [asig pval a a_] = do_correlation(megacube, songs, metrics, algos, algo_groups, merge_algos, merge_songs, merge_dsets, metric_labels, bonferroni) jordan@2: jordan@2: % function [asig pval a a_] = do_correlation(megacube, songs, metrics, algos, algo_groups, merge_algos, merge_songs, merge_dsets, metric_labels, bonferroni) jordan@2: % jordan@2: % Script to make and analyze correlation plot. jordan@2: % Example usage: jordan@2: % To run your first experiment (Fig 1a) request: jordan@2: % do_correlation(megacube, lab_measures, sind_manual1, [1:9], -1, 0, 1, -1, s_manual1) jordan@2: % jordan@2: % MEGACUBE is the giant (N songs) x (M metrics) x (L algorithms) matrix of evaluation results. jordan@2: % SONGS, METRICS and ALGOS are the indices into these three dimensions desired. jordan@2: % ALGO_GROUPS indicates groups of algorithms that should be averaged together rather than counted separately. jordan@2: % (this has not yet been implemented) jordan@2: % Set MERGE_ALGOS > 0 in order to compute the median score across algorithms. jordan@2: % Set MERGE_SONGS > 0 in order to compute the median score across songs. jordan@2: % MERGE_DSETS is also not yet implemented. jordan@2: % METRIC_LABELS is a matrix of strings, one for each of the METRICS, for use in plotting. jordan@2: % Set BONFERRONI > 0 in order to apply a bonferroni correction of BONFERRONI. (Default value: 0.05.) jordan@2: % Note a few hard-coded decisions, such as: jordan@2: % - significance level hard coded as 0.05. jordan@2: % - in the image, decision that tau > 0.8 is strong, tau > 0.33 is weak, and tau < 0.33 is nothing. jordan@2: jordan@2: % Defaults and hard coding values: jordan@2: if nargin<10, jordan@2: bonferroni = 0.05; jordan@2: end jordan@2: significant_p = 0.05; jordan@2: maxtau = 0.8; jordan@2: mintau = 0.33; jordan@2: jordan@2: jordan@2: jordan@2: tmpcube = megacube(songs,metrics,algos); jordan@2: jordan@2: % if exist('algo_groups'), jordan@2: % for i=1:length(algo_groups), jordan@2: % merge the groups somehow... jordan@2: % end jordan@2: % end jordan@2: jordan@2: if merge_algos>0, % If we merge algorithms, take the median score across algorithms. jordan@2: tmpcube = median(tmpcube,3); jordan@2: elseif merge_songs>0, % If we merge songs, take the median score across songs. jordan@2: tmpcube = median(tmpcube,1); % Then, resize the matrix to be 2-d: jordan@2: tmpcube = transpose(reshape(tmpcube,size(tmpcube,2),size(tmpcube,3))); jordan@2: end jordan@2: jordan@2: % Compute Kendall tau correlation: jordan@2: [a pval] = corr(tmpcube,'type','Kendall'); jordan@2: % Apply bonferroni correction: jordan@2: m = length(a)*(length(a)-1)/2; jordan@2: asig = pval0, jordan@2: fprintf('Bonferroni applied.\n') jordan@2: asig = (pval*m)=maxtau) + (abs(a)>=mintau); jordan@2: a_ = tril(a_,-1); jordan@2: jordan@2: % A contains the correlation values themselves. jordan@2: % ASIG is a binary matrix that states whether the correlation is statistically significant. jordan@2: % A_ is a matrix of -2, -1, 0, 1 and 2s that says whether a correlation is qualitatively strong (2), qualitatively weak (1), or nada (0). jordan@2: % Sometimes values will be statistically significant, but qualitatively insignificant. We do not want to bother looking at these, so jordan@2: % let us make our pretty picture carefully. jordan@2: jordan@2: % The values we display will always be straight from A. The colour we display, to emphasize the strong correlations, jordan@2: % should be the element-wise product of A, ASIG, and A_. jordan@2: % Also: jordan@2: % Iff tau>0.33 (a_>0), include text. jordan@2: % Iff tau is significant (asig=1), include background. jordan@2: % Iff tau>0.8 (a_=2), put in bold. jordan@2: % Iff tau>0.8 AND tau is significant, invert the color of the text (because the colour will be darker). jordan@2: jordan@2: img = a_.*a.*asig; jordan@2: img = img(2:end,1:end-1); % ignore the diagonal jordan@2: clf jordan@2: imagesc(img, [-1 1]) jordan@2: for i=1:length(a_), jordan@2: for j=1:length(a_), jordan@2: if a_(i,j)>0, jordan@2: % tau is >0.33 so we definitely write the value. need to determine fontface and colour. jordan@2: % if tau>.8, put in bold jordan@2: if abs(a_(i,j))>1, jordan@2: fontw = 'bold'; jordan@2: else jordan@2: fontw = 'normal'; jordan@2: end jordan@2: if abs(a_(i,j))>1 & asig(i,j)==1, jordan@2: textcolor = [1 1 1]; jordan@2: else jordan@2: textcolor = [0 0 0]; jordan@2: end jordan@2: % h = text(j-.35,i-1,num2str(a(i,j),2),'Color',textcolor); jordan@2: h = text(j,i-1,sprintf('%.2f',a(i,j)),'Color',textcolor,'FontWeight',fontw,'FontSize',12,'HorizontalAlignment','center'); jordan@2: set(h,'HorizontalAlignment','center') jordan@2: end jordan@2: end jordan@2: end jordan@2: cmap_el = transpose([linspace(.3,1,50)]); jordan@2: cmap = repmat(cmap_el,1,3); jordan@2: cmap = [cmap; flipud(cmap)]; jordan@2: % Alternatively: jordan@2: cmap = [ones(size(cmap_el)) cmap_el cmap_el; flipud([cmap_el cmap_el ones(size(cmap_el))])]; jordan@2: colormap(cmap); jordan@2: jordan@2: set(gca,'YTickLabel',metric_labels(2:end),'YTick',(1:length(a)-1),'FontAngle','italic','FontSize',12) jordan@2: set(gca,'XTickLabel',metric_labels(1:end-1),'XTick',(1:length(a)-1),'FontAngle','italic','FontSize',12) jordan@2: % set(gcf,'Position',[1000,1000,700,300]) jordan@2: % set(gca,'XTickLabel',metric_labels(2:2:end),'YTick',(1:length(a)/2)) jordan@2: jordan@2: % axis([0.5, length(a)-.5, 1.5, length(a)+.5])