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

This commit is contained in:
leo 2023-02-06 22:05:01 +01:00
parent c5f5be1ca9
commit b785da87e9
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -167,4 +167,30 @@ func Schaffer(x []float64) float64 { return 0 }
// Weierstrass is the "Weierstrass Function" of CEC2020 with a=0.5, b=3 and // Weierstrass is the "Weierstrass Function" of CEC2020 with a=0.5, b=3 and
// kmax=20. // kmax=20.
func Weierstrass(x []float64) float64 { return 0 } func Weierstrass(x []float64) float64 {
a := 0.5
b := 3.0
kmax := 20.0
// float64 version of the length of x.
fnx := float64(len(x))
var sum1 float64
var sum2 float64
for i := range x {
var ksum float64
for k := 0.0; k < kmax; k++ {
ksum += math.Pow(a, k) * math.Cos(2*math.Pi*math.Pow(b, k)*(x[i]+0.5))
}
sum1 += ksum
}
for k := 0.0; k < kmax; k++ {
sum2 += math.Pow(a, k) * math.Cos(2*math.Pi*math.Pow(b, k)*0.5)
}
return sum1 - (fnx * sum2)
}