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

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

@ -80,7 +80,28 @@ func Griewank(x []float64) float64 {
func Ackley(x []float64) float64 { return 0 }
// Happycat is the "Happycat Function" of CEC2020.
func Happycat(x []float64) float64 { return 0 }
func Happycat(x []float64) float64 {
var sum1 float64
var sum2 float64
var sum3 float64
// float64 version of the length of x.
fnx := float64(len(x))
for i := range x {
xipow2 := math.Pow(x[i], 2)
sum1 += xipow2 - fnx
sum2 += xipow2
sum3 += x[i]
}
return math.Pow(math.Abs(sum1), 0.25) + (((0.5 * sum2) + sum3) / (fnx + 0.5))
}
// Discus is the "Discus Function" of CEC2020.
func Discus(x []float64) float64 {