Fixed algorithm mistakes. There was "index out of bounds" situation.

This commit is contained in:
E––jenY-Poltavchiny 2023-06-24 14:14:06 +03:00
parent 4ba1a1606a
commit c6e1eb8406

View File

@ -62,10 +62,16 @@ public fun DoubleFieldOpsND.dynamicTimeWarping(series1 : DoubleBuffer, series2 :
pathLength++ pathLength++
while (index1 != 0 || index2 != 0) { while (index1 != 0 || index2 != 0) {
when { when {
index1 == 0 || costMatrix[index1, index2] == costMatrix[index1, index2 - 1] + abs(series1[index1] - series2[index2]) -> { index1 == 0 -> {
index2-- index2--
} }
index2 == 0 || costMatrix[index1, index2] == costMatrix[index1 - 1, index2] + abs(series1[index1] - series2[index2]) -> { index2 == 0 -> {
index1--
}
costMatrix[index1, index2] == costMatrix[index1, index2 - 1] + abs(series1[index1] - series2[index2]) -> {
index2--
}
costMatrix[index1, index2] == costMatrix[index1 - 1, index2] + abs(series1[index1] - series2[index2]) -> {
index1-- index1--
} }
costMatrix[index1, index2] == costMatrix[index1 - 1, index2 - 1] + abs(series1[index1] - series2[index2]) -> { costMatrix[index1, index2] == costMatrix[index1 - 1, index2 - 1] + abs(series1[index1] - series2[index2]) -> {