math-optim/bench/functions.go
surtur 65d555b4df
All checks were successful
continuous-integration/drone/push Build is passing
fix: correct function definitions (swap De Jongs)
2022-06-17 20:41:39 +02:00

42 lines
816 B
Go

// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package bench
import "math"
var Functions = []string{"Schwefel", "De Jong 1st", "De Jong 2nd"}
// Schwefel computes a value of the Schwefel function for x.
func Schwefel(x []float64) float64 {
var res float64
for _, val := range x {
res += val * math.Sin(math.Sqrt(math.Abs(val)))
}
return 418.9829*float64(len(x)) - res
}
// DeJong1st computes the value of the 1st De Jong function for x.
func DeJong1st(x []float64) float64 {
var res float64
for _, val := range x {
res += math.Pow(val, 2)
}
return res
}
// DeJong2nd computes the value of the 2nd De Jong function for x.
func DeJong2nd(x []float64) float64 {
var res float64
for _, val := range x {
res += math.Floor(val)
}
return res
}