cec2020: implement Weierstrass func
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c5f5be1ca9
commit
b785da87e9
@ -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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user