nSeq
.
tSeq
to the new array.
DTWTemplate
, set values
point to the new array and set length=nSeq
.
DTWTemplate
to the templates
vector.
templates
.
templates[tIndex]
exists and doesn't point to NULL. Otherwise, return 1.
values
array from the DTWTemplate
in question.
DTWTemplate
in question.
templates[tIndex]
point to NULL.
templates[tIndex]
exists and doesn't point to NULL. Otherwise, return NULL.
*nSeq
.
params.dmetrics=DTW_DMETRICS
set
obsder=calcDerivatives(observation,n)
avgcost
=0.
params.dmetrics=DTW_DMETRICS
set
tempder=calcDerivatives(template,m)
x,y
(depending on params.seoffset
) do
createWarpingGrid(x,y,o,sqrDist,observation,template)
or
createWarpingGrid(x,y,o,sqrDist,obsder,tempder)
(Depending on selected metrics)
thiscost=warpinggrid[a][b].costsofar/
warpinggrid[a][b].lengthsofar
thiscost
< avgcost
, set avgcost=thiscost
DTWAllResultElement
s.
avgcost
is first etc.
params.dmetrics=DTW_DMETRICS
set
obsder=calcDerivatives(observation,n)
tempder=calcDerivatives(template,m)
avgcost
=0.
x,y
(depending on params.seoffset
) do
createWarpingGrid(x,y,o,sqrDist,observation,template)
or
createWarpingGrid(x,y,o,sqrDist,obsder,tempder)
(Depending on selected metrics)
thiscost=warpinggrid[a][b].costsofar/
warpinggrid[a][b].lengthsofar
thiscost
< avgcost
, set avgcost=thiscost, sa=a, sb=b,
sx=x, sy=y
.
createWarpingGrid(sx,sy,o,dist)
(creates again the warping grid with best start point)
i=sa j=sb do warpingpath.push({i,j}) temp=i i=warpinggrid[i][j].previ j=warpinggrid[temp][j].prevj while(i != sx) OR (j != sy) warpingpath.push({i,j})
warpingpath
.
warpingpath
into an array.
createWarpingGrid (Internal function)
warpinggrid[x][y].costsofar=dist(x,y) warpinggrid[x][y].lengthsofar=1 for i = x to n-1 do for j = MAX(y ; i-o) to MIN(m-1 ; i+o) do --Select point (a,b) from points (i-1,j), (i-1,j-1) and --(i,j-1) so that (warpinggrid[a][b].costsofar+dist(i,j))/ --(warpinggrid[a][b].lengthsofar+1) is minimized warpinggrid[i][j].costsofar= warpinggrid[a][b].costsofar+dist(i,j) warpinggrid[i][j].lengthsofar= warpinggrid[a][b].lengthsofar+1 warpinggrid[i][j].previ=a warpinggrid[i][j].prevj=b end end return warpinggrid
Here,
warpinggrid
is a (WarpingGridPoint
s.
(x,y)
is the starting point of the path (a parameter).
o
is the warping windw width (a parameter).
dist
is a function pointer (a parameter). The function calculates the distance between observation point sqrDist (Internal function)
return (observation[i]-template[j])^2
observation
is an array of floats (parameter)
i
is the index number of the element of observation (parameter)
template
is an array of floats (parameter)
j
is the index number of the element of template (parameter)
observation
and template
point to bare sample vectors. When the selected metrics is derivative metrics,
observation
and template
point to vectors containing estimated derivatives that are calculated prior
to calling the CreateWarpingGrid
function.
calcDerivatives (Internal function)
for i = 1 to l-2 do deriv[i]=((vector[i]-vector[i-1])+(vector[i+1] -vector[i-1])/2)/2 end deriv[0]=deriv[1] deriv[l-1] = deriv[l-2] return deriv
vector
contains the original sample (parameter)
l
is the length of the original sample (parameter)
deriv
contains the calculated estimated derivatives.