changeset 8270:be49b09312d0 octave-forge

support fast version without resolving ties (MODE='advanced-ties')
author schloegl
date Wed, 10 Aug 2011 13:20:17 +0000
parents c3ac9ac011d3
children e1a47accb4ef
files extra/NaN/inst/ranks.m
diffstat 1 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/inst/ranks.m	Wed Aug 10 11:32:16 2011 +0000
+++ b/extra/NaN/inst/ranks.m	Wed Aug 10 13:20:17 2011 +0000
@@ -16,6 +16,11 @@
 % r = ranks(X,DIM,'advanced   ')
 %   implements an advanced algorithm with O(n*log(n)) computational 
 %   and O(n.log(n)) memory effort
+% r = ranks(X,DIM,'advanced-ties')
+%   implements an advanced algorithm with O(n*log(n)) computational 
+%   and O(n.log(n)) memory effort
+%   but without correction for ties 
+%   This is the fastest algorithm 
 %
 % see also: CORRCOEF, SPEARMAN, RANKCORR
 %
@@ -83,7 +88,7 @@
         end;
         % r(r<1)=NaN;
         
-elseif strcmp(Mode(1:min(12,length(Mode))),'mtraditional'), % advanced
+elseif strcmp(Mode(1:min(12,length(Mode))),'mtraditional'), 
         % + memory effort is lower
         
 	r = zeros(size(X));
@@ -94,7 +99,19 @@
         end;
         % r(r<1)=NaN;
         
-elseif strcmp(Mode(1:min(11,length(Mode))),'advanced   '), % advanced
+elseif strcmp(Mode(1:min(13,length(Mode))),'advanced-ties'), % advanced
+        % + uses sorting, hence needs only O(m.n.log(n)) computations         
+        % - does not fix ties
+
+        r = zeros(size(X));
+        [sX, ix] = sort(X,1); 
+	for k=1:M,
+	        [tmp,r(:,k)] = sort(ix(:,k),1);	    % r yields the rank of each element 	
+	end;        
+	r(isnan(X)) = nan;
+
+        
+elseif strcmp(Mode(1:min(8,length(Mode))),'advanced'), % advanced
         % + uses sorting, hence needs only O(m.n.log(n)) computations         
         
         % [tmp,ix] = sort([X,Y]);