Remove unnecessary code from outer sift() function

This commit is contained in:
Igor Dunaev 2024-04-28 18:36:54 +03:00
parent 1c5113da29
commit 40ffa8d6fc

View File

@ -76,17 +76,7 @@ public class EmpiricalModeDecomposition<BA, L: Number> (
* @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<Double>): 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<Double>): SiftingResult = siftInner(signal, 1, 0)
/**
* Compute a single iteration of the sifting process.
@ -96,7 +86,9 @@ public class EmpiricalModeDecomposition<BA, L: Number> (
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 {