cec2020: implement Ackley func
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-06 15:48:03 +01:00
parent 9795287dc9
commit 83a8c94ea9
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -77,7 +77,22 @@ func Griewank(x []float64) float64 {
}
// Ackley is the "Ackley's Function" of CEC2020.
func Ackley(x []float64) float64 { return 0 }
func Ackley(x []float64) float64 {
var sum1 float64
var sum2 float64
for i := range x {
sum1 += math.Pow(x[i], 2)
sum2 += math.Cos(2 * math.Pi * x[i])
}
// float64 version of the length of x.
fnx := float64(len(x))
return -20*math.Exp(-0.2*math.Sqrt((1/fnx)*sum1)) - math.Exp((1/fnx)*sum2) + 20 + math.E
}
// Happycat is the "Happycat Function" of CEC2020.
func Happycat(x []float64) float64 {