fix: correct Lunacek Bi-Rastrigin 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
e846fe25e5
commit
3933dc608a
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user