DTW method realization #517
@ -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))
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,31 +6,29 @@
|
|||||||
package space.kscience.kmath.series
|
package space.kscience.kmath.series
|
||||||
|
|
||||||
import space.kscience.kmath.nd.*
|
import space.kscience.kmath.nd.*
|
||||||
import space.kscience.kmath.operations.DoubleField
|
|
||||||
import space.kscience.kmath.operations.algebra
|
import space.kscience.kmath.operations.algebra
|
||||||
import space.kscience.kmath.operations.bufferAlgebra
|
import space.kscience.kmath.operations.bufferAlgebra
|
||||||
import space.kscience.kmath.structures.DoubleBuffer
|
|
||||||
import space.kscience.kmath.structures.asBuffer
|
import space.kscience.kmath.structures.asBuffer
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class DTWTest {
|
class DTWTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun someData() : Unit {
|
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 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 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 seriesOne: Series<Double> = firstSequence.asBuffer().moveTo(0)
|
||||||
val seriesTwo: DoubleBuffer = secondSequence.asBuffer()
|
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}")
|
println("Total penalty coefficient: ${result.totalCost}")
|
||||||
print("Alignment: ")
|
print("Alignment: ")
|
||||||
println(result.alignMatrix)
|
println(result.alignMatrix)
|
||||||
for ((i , j) in result.alignMatrix.indices) {
|
for ((i , j) in result.alignMatrix.indices) {
|
||||||
if (result.alignMatrix[i, j] == 1) {
|
if (result.alignMatrix[i, j] > 0.0) {
|
||||||
print("[$i, $j] ")
|
print("[$i, $j] ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user