From 47a9bf0e9a3bb64dfea92f16f82485b9f0468dd6 Mon Sep 17 00:00:00 2001 From: Igor Dunaev Date: Fri, 3 May 2024 22:37:59 +0300 Subject: [PATCH] Suboptimal implementation for countExtrema --- .../kscience/kmath/series/EmpiricalModeDecomposition.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/EmpiricalModeDecomposition.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/EmpiricalModeDecomposition.kt index 301247698..ea8a0aa62 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/EmpiricalModeDecomposition.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/EmpiricalModeDecomposition.kt @@ -196,16 +196,12 @@ private fun SeriesAlgebra.relativeDifference( .div(previous pow 2) .fold(0.0) { acc, d -> acc + d } // TODO replace with Series<>.sum() method when it's implemented -private fun > isExtreme(prev: T, elem: T, next: T): Boolean = - (elem > prev && elem > next) || (elem < prev && elem < next) - /** * Brute force count all extrema of a series. */ -@Deprecated("Does not match the algorithm currently in use.") private fun Series.countExtrema(): Int { require(size >= 3) { "Expected series with at least 3 elements, but got $size elements" } - return (1 .. size - 2).count { isExtreme(this[it - 1], this[it], this[it + 1]) } + return peaks().size + troughs().size } /**