From d950ce51fada59de669da9284a2eaf987866ce0c Mon Sep 17 00:00:00 2001 From: marwan <> Date: Wed, 2 Jul 2008 11:59:22 +0000 Subject: [PATCH] new norms: DTW and Levenshtein bug fix for logical data vectors --- crp.m | 81 +++++++++++++++++++++++++++++++++++++++++++--------------- crp2.m | 36 ++++++++++++++------------ 2 files changed, 81 insertions(+), 36 deletions(-) diff --git a/crp.m b/crp.m index 485156a..3238ca8 100644 --- a/crp.m +++ b/crp.m @@ -70,7 +70,7 @@ function xout=crp(varargin) % b = sin(.01 * ([1:1000] * 2 * pi/67) .^ 2); % crp(a,b,3,12,'distance') % -% See also CRP2, CRP_BIG, JRP, CRQA. +% See also CRP2, CRP_BIG, JRP, TAUCRP, CRQA. % Copyright (c) 1998-2007 by AMRON % Norbert Marwan, Potsdam University, Germany @@ -80,6 +80,9 @@ function xout=crp(varargin) % $Revision$ % % $Log$ +% Revision 5.13 2007/07/18 17:18:44 marwan +% integer values in the arguments supported +% % Revision 5.12 2007/05/15 17:33:13 marwan % new neighbourhood criterion: fixed RR % @@ -167,28 +170,30 @@ set(0,'ShowHidden','On') error(nargchk(1,8,nargin)); if nargout>1, error('Too many output arguments'), end -check_meth={'ma','eu','mi','nr','rr','fa','in','om','op','di'}; % maxnorm, euclidean, nrmnorm, fan, distance +check_meth={'ma','eu','mi','nr','rr','fa','in','om','op','le','dt','di'}; % maxnorm, euclidean, nrmnorm, fan, distance check_norm={'non','nor'}; % nonormalize, normalize check_gui={'gui','nog','sil'}; % gui, nogui, silent -if isnumeric(varargin{1})==1 % read commandline input +% transform any int to double +intclasses = {'uint8';'uint16';'uint32';'uint64';'int8';'int16';'int32';'int64';'logical'}; +flagClass = []; +for i = 1:length(intclasses) + i_int=find(cellfun('isclass',varargin,intclasses{i})); + if ~isempty(i_int) + for j = 1:length(i_int) + varargin{i_int(j)} = double(varargin{i_int(j)}); + end + flagClass = [flagClass; i_int(:)]; + end +end +if ~isempty(flagClass) + disp(['Warning: Input arguments at position [',num2str(flagClass'),'] contain integer values']); + disp(['(now converted to double).']) +end + + +if isnumeric(varargin{1}) % read commandline input varargin{9}=[]; - % transform any int to double - intclasses = {'uint8';'uint16';'uint32';'uint64';'int8';'int16';'int32';'int64'}; - flagClass = []; - for i = 1:length(intclasses) - i_int=find(cellfun('isclass',varargin,intclasses{i})); - if ~isempty(i_int) - for j = 1:length(i_int) - varargin{i_int(j)} = double(varargin{i_int(j)}); - end - flagClass = [flagClass; i_int(:)]; - end - end - if ~isempty(flagClass) - disp(['Warning: Input arguments at position [',num2str(flagClass'),'] contain integer values']); - disp(['(now converted to double).']) - end i_double=find(cellfun('isclass',varargin,'double')); i_char=find(cellfun('isclass',varargin,'char')); @@ -280,6 +285,7 @@ if isnumeric(varargin{1})==1 % read commandline input if nonorm==1, x=(x-mean(x))/std(x); end xscale=(1:length(x))'; end + if size(y,2)>=2 yscale=y(:,1); if ~isempty(find(diff(yscale)<0)), error('First column of the second vector must be monotonically non-decreasing.'),end @@ -389,6 +395,8 @@ if nogui>0 tx(8)={'order matrix'}; tx(9)={'order pattern'}; tx(10)={'distance plot'}; + tx(11)={'distance plot'}; + tx(12)={'distance plot'}; disp(['use method: ', char(tx(method))]); if nonorm==1, disp('normalize data'); else disp('do not normalize data'); end end @@ -402,7 +410,7 @@ end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% switch routines -try +try switch(action) @@ -840,6 +848,39 @@ switch(action) matext=''; + %%%%%%%%%%%%%%%%% Levenshtein + + case 10 + + errcode=120; + + set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Compute Distance Matrix'),drawnow + px = permute(x2, [ 1 3 2 ]); + py = permute(y2, [ 3 1 2 ]); + px2 = reshape(px(:,ones(1,NY),:),NX*NY,m); + py2 = reshape(py(ones(1,NX),:,:),NX*NY,m); + s1 = levenshtein(px2, py2); + X = reshape(s1,NX,NY)'; + matext=''; + + + %%%%%%%%%%%%%%%%% DTW + + case 11 + + errcode=121; + + set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Compute Distance Matrix'),drawnow + px = permute(x2, [ 1 3 2 ]); + py = permute(y2, [ 3 1 2 ]); + px2 = reshape(px(:,ones(1,NY),:),NX*NY,m); + py2 = reshape(py(ones(1,NX),:,:),NX*NY,m); + s1 = dtw(px2, py2); + X = reshape(s1,NX,NY)'; + matext=''; + + + %%%%%%%%%%%%%%%%% global CRP case length(check_meth) diff --git a/crp2.m b/crp2.m index 863033b..6400bef 100644 --- a/crp2.m +++ b/crp2.m @@ -82,6 +82,9 @@ function xout=crp2(varargin) % $Revision$ % % $Log$ +% Revision 5.15 2008/04/29 14:52:01 marwan +% levenshtein and DTW distance added +% % Revision 5.14 2007/07/18 17:18:44 marwan % integer values in the arguments supported % @@ -183,24 +186,25 @@ check_meth={'ma','eu','mi','nr','rr','fa','in','om','op','le','dt','di'}; % max check_norm={'non','nor'}; % nonormalize, normalize check_gui={'gui','nog','sil'}; % gui, nogui, silent -if isnumeric(varargin{1}) % read commandline input - varargin{9}=[]; - % transform any int to double - intclasses = {'uint8';'uint16';'uint32';'uint64';'int8';'int16';'int32';'int64'}; - flagClass = []; - for i = 1:length(intclasses) - i_int=find(cellfun('isclass',varargin,intclasses{i})); - if ~isempty(i_int) - for j = 1:length(i_int) - varargin{i_int(j)} = double(varargin{i_int(j)}); - end - flagClass = [flagClass; i_int(:)]; +% transform any int to double +intclasses = {'uint8';'uint16';'uint32';'uint64';'int8';'int16';'int32';'int64';'logical'}; +flagClass = []; +for i = 1:length(intclasses) + i_int=find(cellfun('isclass',varargin,intclasses{i})); + if ~isempty(i_int) + for j = 1:length(i_int) + varargin{i_int(j)} = double(varargin{i_int(j)}); end + flagClass = [flagClass; i_int(:)]; end - if ~isempty(flagClass) - disp(['Warning: Input arguments at position [',num2str(flagClass'),'] contain integer values']); - disp(['(now converted to double).']) - end +end +if ~isempty(flagClass) + disp(['Warning: Input arguments at position [',num2str(flagClass'),'] contain integer values']); + disp(['(now converted to double).']) +end + +if isnumeric(varargin{1}) % read commandline input + varargin{9}=[]; i_double=find(cellfun('isclass',varargin,'double')); i_char=find(cellfun('isclass',varargin,'char')); -- GitLab