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
|
d := 1.0
|
||||||
mu0 := 2.5
|
mu0 := 2.5
|
||||||
mu1 := -math.Sqrt((math.Pow(mu0, 2) - d) / s)
|
mu1 := -math.Sqrt((math.Pow(mu0, 2) - d) / s)
|
||||||
xhat := make([]float64, nx)
|
xhat := getMean(x)
|
||||||
xopt := newXopt(nx, mu0)
|
|
||||||
|
|
||||||
for i := range x {
|
for i := range x {
|
||||||
xhat = append(xhat, 2*x[i])
|
sum0 += math.Pow(xhat-mu0, 2)
|
||||||
|
|
||||||
if xopt[i] < 0 {
|
sum1 += math.Pow(xhat-mu1, 2)
|
||||||
xhat[i] *= -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range x {
|
zi := math.Pow(100, 0.5*((float64(i)-1)/fnx-1)) * xhat
|
||||||
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]
|
|
||||||
|
|
||||||
sum2 += (1 - math.Cos(2*math.Pi*zi))
|
sum2 += (1 - math.Cos(2*math.Pi*zi))
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/exp/rand"
|
"golang.org/x/exp/rand"
|
||||||
|
|
||||||
|
"gonum.org/v1/gonum/stat"
|
||||||
"gonum.org/v1/gonum/stat/distuv"
|
"gonum.org/v1/gonum/stat/distuv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -110,6 +111,7 @@ func GetMaxFES(dim int) int {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint: unused
|
||||||
func newXopt(n int, mu0 float64) []float64 {
|
func newXopt(n int, mu0 float64) []float64 {
|
||||||
gaussDist := &distuv.Normal{
|
gaussDist := &distuv.Normal{
|
||||||
Src: rand.NewSource(uint64(time.Now().UnixNano())),
|
Src: rand.NewSource(uint64(time.Now().UnixNano())),
|
||||||
@ -182,6 +184,12 @@ func getMz(x []float64, z []float64) []float64 {
|
|||||||
return mz
|
return mz
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMean(x []float64) float64 {
|
||||||
|
mean := stat.Mean(x, nil)
|
||||||
|
|
||||||
|
return mean
|
||||||
|
}
|
||||||
|
|
||||||
func getWeight(x, o []float64, sigma, nx float64) float64 {
|
func getWeight(x, o []float64, sigma, nx float64) float64 {
|
||||||
var sum float64
|
var sum float64
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user