From 3933dc608a4175eae1e75dba1983b35f7347a2a4 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 12 Feb 2023 10:41:21 +0100 Subject: [PATCH] fix: correct Lunacek Bi-Rastrigin func --- bench/cec2020/benchFunctions.go | 17 ++++------------- bench/cec2020/helperFunctions.go | 8 ++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/bench/cec2020/benchFunctions.go b/bench/cec2020/benchFunctions.go index 63c4176..b098c4d 100644 --- a/bench/cec2020/benchFunctions.go +++ b/bench/cec2020/benchFunctions.go @@ -36,23 +36,14 @@ func LunacekBiRastrigin(x []float64) float64 { d := 1.0 mu0 := 2.5 mu1 := -math.Sqrt((math.Pow(mu0, 2) - d) / s) - xhat := make([]float64, nx) - xopt := newXopt(nx, mu0) + xhat := getMean(x) for i := range x { - xhat = append(xhat, 2*x[i]) + sum0 += math.Pow(xhat-mu0, 2) - if xopt[i] < 0 { - xhat[i] *= -1 - } - } + sum1 += math.Pow(xhat-mu1, 2) - for i := range x { - sum0 += math.Pow(xhat[i]-mu0, 2) - - sum1 += math.Pow(xhat[i]-mu1, 2) - - zi := math.Pow(100, 0.5*((float64(i)-1)/fnx-1)) * xhat[i] + zi := math.Pow(100, 0.5*((float64(i)-1)/fnx-1)) * xhat sum2 += (1 - math.Cos(2*math.Pi*zi)) } diff --git a/bench/cec2020/helperFunctions.go b/bench/cec2020/helperFunctions.go index 22acc5d..79147d1 100644 --- a/bench/cec2020/helperFunctions.go +++ b/bench/cec2020/helperFunctions.go @@ -9,6 +9,7 @@ import ( "golang.org/x/exp/rand" + "gonum.org/v1/gonum/stat" "gonum.org/v1/gonum/stat/distuv" ) @@ -110,6 +111,7 @@ func GetMaxFES(dim int) int { return -1 } +// nolint: unused func newXopt(n int, mu0 float64) []float64 { gaussDist := &distuv.Normal{ Src: rand.NewSource(uint64(time.Now().UnixNano())), @@ -182,6 +184,12 @@ func getMz(x []float64, z []float64) []float64 { return mz } +func getMean(x []float64) float64 { + mean := stat.Mean(x, nil) + + return mean +} + func getWeight(x, o []float64, sigma, nx float64) float64 { var sum float64