DTW method realization #517

Open
EjenY-Poltavchiny wants to merge 19 commits from mrFendel/ejeny_branch_ into dev
2 changed files with 8 additions and 33 deletions
Showing only changes of commit 1773b49b1f - Show all commits

View File

@ -1,23 +0,0 @@
/*
* Copyright 2018-2023 KMath contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package space.kscience.kmath.structures
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.operations.buffer
import space.kscience.kmath.operations.bufferAlgebra
import space.kscience.kmath.operations.withSize
//inline fun <reified R : Any> MutableBuffer.Companion.same(
// n: Int,
// value: R
//): MutableBuffer<R> = auto(n) { value }
fun main() {
with(DoubleField.bufferAlgebra.withSize(5)) {
println(number(2.0) + buffer(1, 2, 10, 4, 9))
}
}

View File

@ -6,33 +6,31 @@
package space.kscience.kmath.series
import space.kscience.kmath.nd.*
import space.kscience.kmath.operations.DoubleField
import space.kscience.kmath.operations.algebra
import space.kscience.kmath.operations.bufferAlgebra
import space.kscience.kmath.structures.DoubleBuffer
import space.kscience.kmath.structures.asBuffer
import kotlin.test.Test
import kotlin.test.assertEquals
class DTWTest {
@Test
fun someData() : Unit {
with(Double.algebra.bufferAlgebra) {
with(Double.algebra.bufferAlgebra.seriesAlgebra()) {
val firstSequence: DoubleArray = doubleArrayOf(0.0, 2.0, 3.0, 1.0, 3.0, 0.1, 0.0, 1.0)
val secondSequence: DoubleArray = doubleArrayOf(1.0, 0.0, 3.0, 0.0, 0.0, 3.0, 2.0, 0.0, 2.0)
val seriesOne: DoubleBuffer = firstSequence.asBuffer()
val seriesTwo: DoubleBuffer = secondSequence.asBuffer()
val seriesOne: Series<Double> = firstSequence.asBuffer().moveTo(0)
val seriesTwo: Series<Double> = secondSequence.asBuffer().moveTo(0)
val result = dynamicTimeWarping(seriesOne, seriesTwo)
val result = DoubleFieldOpsND.dynamicTimeWarping(seriesOne, seriesTwo)
println("Total penalty coefficient: ${result.totalCost}")
print("Alignment: ")
println(result.alignMatrix)
for ((i , j) in result.alignMatrix.indices) {
if (result.alignMatrix[i, j] == 1) {
print("[$i, $j] ")
}
if (result.alignMatrix[i, j] > 0.0) {
print("[$i, $j] ")
}
}
}
}