Cody

# Problem 43478. Calculate the dynamic time warping similarity

Solution 3880038

Submitted on 27 Nov 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
x1 = [0 0 1 2 3 4 3 2 1 0 0 1 0]; x2 = [0 1 2 3 6 3 3 2 1 0 0 0 1 0]; y = 2; assert(isequal(dtw_similarity(x1,x2),y));

ans = 0 0 0 1 4 10 22 35 47 55 52 44 33 21 14 12 7 7 5 3 1 0 0 1 0 0

Output argument "cost" (and maybe others) not assigned during call to "dtw_similarity". Error in Test1 (line 4) assert(isequal(dtw_similarity(x1,x2),y));

2   Fail
x1 = [0 0 1 2 3 4 3 2 1 0 0 1 0]; x2 = [0 1 2 3 4 5 4 4 2 1 0 0 1 2 1 0]; y = 3; assert(isequal(dtw_similarity(x1,x2),y));

ans = 0 0 0 1 4 10 20 33 46 57 62 59 51 38 26 19 17 17 18 14 9 4 1 1 2 1 0 0

Output argument "cost" (and maybe others) not assigned during call to "dtw_similarity". Error in Test2 (line 4) assert(isequal(dtw_similarity(x1,x2),y));

3   Fail
x1 = [0.47,0.84,0.99,0.90,0.59,0.14,-0.35,-0.75,-0.97,-0.95,-0.70,-0.27,... 0.21,0.65,0.93,0.98,0.79,0.41,-0.07,-0.54]; x2 = [0.14,0.48,1.06,0.95,0.78,0.79,0.16,-0.29,-0.38,-1.10,-0.86,-0.71,... -0.64,-0.15,0.01,0.39,0.92,1.14,1.44,0.53,0.33,-0.16,-0.93,-0.93,-1.35]; y = 4.88; assert(abs(dtw_similarity(x1,x2)-y)<1E-10);

ans = Columns 1 through 17 0.0658 0.3432 1.0400 1.9381 2.7286 3.2238 3.0096 1.9181 0.1736 -2.1301 -4.3281 -5.7996 -6.1532 -5.0724 -2.7482 0.4357 3.9508 Columns 18 through 34 7.0387 9.0890 9.1757 7.2796 3.8769 -0.2511 -4.5079 -8.1305 -9.5024 -8.8203 -6.3235 -2.4541 1.2590 4.5058 6.4984 6.7244 5.5147 Columns 35 through 44 3.0531 0.1718 -2.1481 -3.4596 -3.2765 -2.6060 -1.2963 0.0138 0.5967 0.7290

Output argument "cost" (and maybe others) not assigned during call to "dtw_similarity". Error in Test3 (line 6) assert(abs(dtw_similarity(x1,x2)-y)<1E-10);

4   Fail
s = zeros(1,100); for i=1:100, x1 = linspace(1,10,10+i); x2 = linspace(1,10,12+i)+0.1; s(i) = dtw_similarity(x1,x2); end y = [2.8000,2.7692,2.6857,2.6923,2.6714,2.6471,2.6500,2.6192,2.6000,... 2.5910,2.5909,2.5665,2.5545,2.5478,2.5500,2.5333,2.5231,2.5172,... 2.5143,2.5028,2.5000,2.4962,2.4838,2.4857,2.4824,2.4795,2.4789,... 2.4703,2.4684,2.4653,2.4643,2.4606,2.4571,2.4558,2.4522,2.4511,... 2.4522,2.4549,2.4575,2.4600,2.4662,2.4713,2.4808,2.4889,2.4976,... 2.5081,2.5187,2.5293,2.5276,2.5257,2.5258,2.5239,2.5226,2.5220,... 2.5222,2.5195,2.5182,2.5174,2.5176,2.5156,2.5143,2.5137,2.5135,... 2.5115,2.5108,2.5099,2.5081,2.5087,2.5077,2.5068,2.5073,2.5056,... 2.5049,2.5044,2.5030,2.5028,2.5023,2.5015,2.5000,2.5003,2.5000,... 2.4992,2.4981,2.4983,2.4979,2.4975,2.4969,2.4964,2.4959,2.4953,... 2.4953,2.4947,2.4941,2.4936,2.4933,2.4928,2.4925,2.4922,2.4909,... 2.4914]; assert(norm(s-y)<3E-4);

ans = Columns 1 through 17 1.1000 3.9400 9.1950 17.5400 29.6500 46.2000 67.8650 95.3200 129.2400 170.3000 219.1750 264.5500 309.9250 344.4500 368.4600 381.2800 382.2350 Columns 18 through 23 370.6500 345.8500 307.1600 253.9050 185.4100 101.0000

Output argument "cost" (and maybe others) not assigned during call to "dtw_similarity". Error in Test4 (line 5) s(i) = dtw_similarity(x1,x2);

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!