代码拉取完成,页面将自动刷新
package linear
import "math"
// PeakDetect Finds the local maxima and minima ("peaks") in the vector
//
// Returns four arrays -> min indices, min values, max indices, max values
//
// A point is considered a maximum peak if it has the maximal
// value, and was preceded (to the left) by a value lower by DELTA.
func PeakDetect(data []float64, delta float64) ([]int, []float64, []int, []float64) {
minx := make([]int, 0, 0)
maxx := make([]int, 0, 0)
minvals := make([]float64, 0, 0)
maxvals := make([]float64, 0, 0)
xvals := make([]int, len(data), len(data))
for i := 0; i < len(data); i++ {
xvals[i] = i
}
if delta < 0 {
return minx, minvals, maxx, maxvals
}
mn := math.Inf(1)
mx := math.Inf(-1)
mnpos := int(math.NaN())
mxpos := int(math.NaN())
lookForMax := true
for i, val := range data {
if val > mx {
mx = val
mxpos = i
}
if val < mn {
mn = val
mnpos = i
}
if lookForMax {
if val < __lookahead(mx, -delta) {
maxx = append(maxx, mxpos)
maxvals = append(maxvals, mx)
mn = val
mnpos = i
lookForMax = false
}
} else {
if val > __lookahead(mn, +delta) {
minx = append(minx, mnpos)
minvals = append(minvals, mn)
mx = val
mxpos = i
lookForMax = true
}
}
}
return minx, minvals, maxx, maxvals
}
// 评估delta
func __lookahead(x, delta float64) float64 {
// 按比例
return x * (1 + delta)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。