Suboptimal implementation for countExtrema
This commit is contained in:
parent
b8bf56bc42
commit
47a9bf0e9a
@ -196,16 +196,12 @@ private fun <BA> SeriesAlgebra<Double, *, BA, *>.relativeDifference(
|
||||
.div(previous pow 2)
|
||||
.fold(0.0) { acc, d -> acc + d } // TODO replace with Series<>.sum() method when it's implemented
|
||||
|
||||
private fun <T: Comparable<T>> 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<Double>.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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user