fix: correct Lunacek Bi-Rastrigin func
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-12 10:41:21 +01:00
parent e846fe25e5
commit 3933dc608a
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 12 additions and 13 deletions

@ -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))
}

@ -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