Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CRP Toolbox for MATLAB
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Norbert Marwan
CRP Toolbox for MATLAB
Commits
79c96b03
Commit
79c96b03
authored
17 years ago
by
marwan
Browse files
Options
Downloads
Patches
Plain Diff
*** empty log message ***
parent
91025790
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
private/dtw.m
+51
-0
51 additions, 0 deletions
private/dtw.m
private/levenshtein.m
+43
-0
43 additions, 0 deletions
private/levenshtein.m
with
94 additions
and
0 deletions
private/dtw.m
0 → 100644
+
51
−
0
View file @
79c96b03
function
y
=
dtw
(
a
,
b
)
% DTW Calculates the dynamic time warping distance.
% D=DTW(A,B) calculates the dynamic time warping (DTW)
% distance between row vectors A and B. If A and B are
% arrays, DTW distances are calculated for all rows in
% these array, thus D is a column vector of length(A).
% The size(A,1) has to match size(B,1).
%
% Reference:
% Myers, C. S, Rabiner, L. R.:
% A comparative study of several dynamic time-warping algorithms
% for connected word recognition, The Bell System Technical
% Journal, 60(7), 1982, 1389-1409.
% FastDTW: Toward Accurate Dynamic Time Warping in Linear Time
% and Space, Stan Salvador and Philip Chan. Intelligent
% Data Analysis, 2007.
% Copyright (c) 2008 by AMRON
% Norbert Marwan, Potsdam University, Germany
% http://www.agnld.uni-potsdam.de
%
% $Date$
% $Revision$
if
size
(
a
,
1
)
~=
size
(
b
,
1
)
error
(
'Array
''
s dimension 1 does not match.'
)
end
Na
=
size
(
a
,
2
);
Nb
=
size
(
b
,
2
);
y
=
zeros
(
size
(
a
,
1
),
1
);
%h = waitbar(0, 'Calculation DTW distance');
for
k
=
1
:
size
(
a
,
1
),
%if k/100 == fix(k/100), waitbar(k/size(a,1)), end
aa
=
a
(
k
,:)
'; bb = b(k,:)'
;
eucDis
=
(
repmat
(
aa
,
1
,
Nb
)
-
repmat
(
bb
'
,
Na
,
1
))
.^
2
;
D
=
zeros
(
size
(
eucDis
));
D
(
1
,
1
)
=
eucDis
(
1
,
1
);
D
(
2
:
Na
,
1
)
=
eucDis
(
2
:
Na
,
1
)
+
D
((
2
:
Na
)
-
1
,
1
);
D
(
1
,
2
:
Nb
)
=
eucDis
(
1
,
2
:
Nb
)
+
D
(
1
,(
2
:
Nb
)
-
1
);
for
n
=
2
:
Na
for
m
=
2
:
Nb
D
(
n
,
m
)
=
eucDis
(
n
,
m
)
+
min
([
D
(
n
-
1
,
m
),
D
(
n
-
1
,
m
-
1
),
D
(
n
,
m
-
1
)]);
end
end
y
(
k
)
=
D
(
Na
,
Nb
);
end
%delete(h)
This diff is collapsed.
Click to expand it.
private/levenshtein.m
0 → 100644
+
43
−
0
View file @
79c96b03
function
y
=
levenshtein
(
a
,
b
)
% LEVENSHTEIN Calculates the Levenshtein distance.
% D=LEVENSHTEIN(A,B) calculates the Levenshtein distance
% between row vectors A and B. If A and B are arrays,
% Levenshtein distances are calculated for all rows in
% these array, thus D is a column vector of length(A).
% The size(A,1) has to match size(B,1).
%
% Reference:
% Levenshtein, V. I.:
% Binary codes capable of correcting deletions, insertions,
% and reversals, Doklady Akademii Nauk SSSR, 163(4), 1965,
% 845-848, 1965 (Russian).
% English in: Soviet Physics Doklady, 10(8), 1966, 707-710.
% Copyright (c) 2008 by AMRON
% Norbert Marwan, Potsdam University, Germany
% http://www.agnld.uni-potsdam.de
%
% $Date$
% $Revision$
if
size
(
a
,
1
)
~=
size
(
b
,
1
)
error
(
'Array
''
s dimension 1 does not match.'
)
end
Na
=
size
(
a
,
2
);
Nb
=
size
(
b
,
2
);
y
=
zeros
(
size
(
a
,
1
),
1
);
for
k
=
1
:
size
(
a
,
1
)
D
=
zeros
([
Na
+
1
,
Nb
+
1
]);
D
(
1
,:)
=
0
:
Nb
;
D
(:,
1
)
=
0
:
Na
;
for
i
=
2
:
Na
+
1
for
j
=
2
:
Nb
+
1
cost
=
(
b
(
k
,
j
-
1
)
~=
a
(
k
,
i
-
1
));
D
(
i
,
j
)
=
min
([
D
(
i
-
1
,
j
-
1
)
+
cost
,
D
(
i
-
1
,
j
)
+
1
,
D
(
i
,
j
-
1
)
+
1
]);
end
end
y
(
k
)
=
D
(
end
,
end
);
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment