如何更改R包DTW中的每步加权系数

时间:2016-09-25 21:58:11

标签: r r-package

我想更改成本函数的默认步骤模式权重,因为我需要在不使用权重2作为对角线距离的纸张中将其他一些标准化。我读过JSS paper,但我发现其他步骤模式并不是我真正想要的,我想。例如,假设我们有两个timeSeries Q,C:

Q = array(c(0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0),dim=c(8,2))
C = array(c(0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0),dim=c(8,2))

当我计算dtw距离时,我得到了     alignment = dtw(Q,C,keep = TRUE) 使用2.41的alginment $距离和成本矩阵,例如[2,2]元素是2而不是1,因为在选择最小值之间的对角线中2 * d [i,j]的权重或惩罚:

g[i,j] = min( g[i-1,j-1] + 2 * d[i  ,j  ] ,
              g[i  ,j-1] +     d[i  ,j  ] ,
              g[i-1,j  ] +     d[i  ,j  ] )

1 个答案:

答案 0 :(得分:1)

plot(asymmetricP1)
edit(asymmetricP1)
structure(c(1, 1, 1, 2, 2, 3, 3, 3, 1, 0, 0, 1, 0, 2, 1, 0, 2, 
1, 0, 1, 0, 1, 0, 0, -1, 0.5, 0.5, -1, 1, -1, 1, 1), .Dim = c(8L, 4L), class = "stepPattern", npat = 3, norm = "N")

看一下情节,并考虑从右到左排序的分支(即branch1 = 0.5重量) 下面脚本中的所有内容都在绘图(asymmetricP1)和编辑(asymmetricP1)的上下文中

#first 8 digit sequence (1,1,1,2,2,3,3,3....
#branch1: "1,1,1" <- amount of intervals assigned to specificaly branch1; (end, joint, origin) 
#branch2: "2,2" <- only 2 intervals, this is the middle diagnol line.
#branch3: "3,3,3" <- amount of interals
#note: Don't be confused by the numbers themselves, ie. "4,4,4" <- 3 intervals; "2,2,2" <- 3 intervals

#for the next sequences consider:
#the sequence of each branch is to be read as farthest from origin -> 0,0 
#each interval assignment is accounted for in this order

#next 8 digit sequence: 1, 0, 0, 1, 0, 2, 1, 0,
#branch1: 1,0,0 <- interval position in relation to the query index
#branch2: 1,0 <- interval position in relation to the query index
#branch3: 2,1,0 <- interval position in relation to the query index (again see in plot)

#next 8 digit sequence: 2, 1, 0, 1, 0, 1, 0, 0
#branch1: 2,1,0 <- interval position in relation to the REFERENCE index
#branch2: 1,0 <- interval position in relation to the reference index
#branch3: 1,0,0 <- interval position in relation to the reference index (again see in plot)

#next 8 digit sequence: -1, 0.5, 0.5, -1, 1, -1, 1, 1
#note: "-1" is a signal that indicates weighting values follow
#note: notice that for each -1 that occurs, there is one value less, for example branch 1
# .....which has 3 intervals can only contain 2 weights (0.5 and 0.5)
#branch1: -1,0.5,0.5 <- changing the first 0.5 changes weight of [-1:0] segment (query index)
#branch2: -1,1 <- weight of middle branch
#branch3: -1,1,1 <- changing the second 1 changes weight of[-1,0] segment (query index)

#.Dim=c(8L, 4L): 
#8 represents the number of intervals (1,1,1,2,2,3,3,3)
#4 (from what I understand) is the (length of all the branch sequences mentioned previously)/8

#npat = 3
#3 is the number of patterns you described in the structure. ie(1,1,1,2,2,3,3,3)

希望这有帮助,祝你好运!