From 40ffa8d6fc5380a4f2911178f48ab07c4084997f Mon Sep 17 00:00:00 2001 From: Igor Dunaev Date: Sun, 28 Apr 2024 18:36:54 +0300 Subject: [PATCH] Remove unnecessary code from outer sift() function --- .../kmath/series/EmpiricalModeDecomposition.kt | 16 ++++------------ 1 file changed, 4 insertions(+), 12 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 d1f4f43d2..467ea3201 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 @@ -76,17 +76,7 @@ public class EmpiricalModeDecomposition ( * @return [SiftingResult.NotEnoughExtrema] is returned if the signal has too few extrema to extract a mode. * Success of an appropriate type (See [SiftingResult.Success] class) is returned otherwise. */ - private fun sift(signal: Series): SiftingResult = (seriesAlgebra) { - val mean = findMean(signal) ?: return SiftingResult.NotEnoughExtrema - val protoMode = signal.zip(mean) { s, m -> s - m } - val sNumber = if (protoMode.sCondition()) 1 else 0 - return when { - maxSiftIterations == 1 -> SiftingResult.MaxIterationsReached(protoMode) - sNumber >= sConditionThreshold -> SiftingResult.SNumberReached(protoMode) - relativeDifference(protoMode, signal) < siftingDelta * signal.size -> SiftingResult.DeltaReached(protoMode) - else -> siftInner(protoMode, 2, sNumber) - } - } + private fun sift(signal: Series): SiftingResult = siftInner(signal, 1, 0) /** * Compute a single iteration of the sifting process. @@ -96,7 +86,9 @@ public class EmpiricalModeDecomposition ( iterationNumber: Int, sNumber: Int ): SiftingResult = (seriesAlgebra) { - val mean = findMean(prevMode) ?: return SiftingResult.SignalFlattened(prevMode) + val mean = findMean(prevMode) ?: + return if (iterationNumber == 1) SiftingResult.NotEnoughExtrema + else SiftingResult.SignalFlattened(prevMode) val mode = prevMode.zip(mean) { p, m -> p - m } val newSNumber = if (mode.sCondition()) sNumber + 1 else sNumber return when {