From c6e1eb8406666df8b4acaa428f5a907dbda9d322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=C2=96=C2=96jenY-Poltavchiny?= Date: Sat, 24 Jun 2023 14:14:06 +0300 Subject: [PATCH] Fixed algorithm mistakes. There was "index out of bounds" situation. --- .../space/kscience/kmath/series/DynamicTimeWarping.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/DynamicTimeWarping.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/DynamicTimeWarping.kt index 72737ae57..e3cc4531c 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/DynamicTimeWarping.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/DynamicTimeWarping.kt @@ -62,10 +62,16 @@ public fun DoubleFieldOpsND.dynamicTimeWarping(series1 : DoubleBuffer, series2 : pathLength++ while (index1 != 0 || index2 != 0) { when { - index1 == 0 || costMatrix[index1, index2] == costMatrix[index1, index2 - 1] + abs(series1[index1] - series2[index2]) -> { + index1 == 0 -> { 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-- } costMatrix[index1, index2] == costMatrix[index1 - 1, index2 - 1] + abs(series1[index1] - series2[index2]) -> {