cec2020: implement LunacekBiRastrigin func
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-07 22:54:15 +01:00
parent cf176f054e
commit 9d4f0f730c
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
4 changed files with 79 additions and 2 deletions

@ -48,7 +48,42 @@ func Schwefel(x []float64) float64 {
} }
// LunacekBiRastrigin is the "Shifted and Rotated Lunacek bi-Rastrigin Function" of CEC2020. // LunacekBiRastrigin is the "Shifted and Rotated Lunacek bi-Rastrigin Function" of CEC2020.
func LunacekBiRastrigin(x []float64) float64 { return 0 } func LunacekBiRastrigin(x []float64) float64 {
var sum0 float64
var sum1 float64
var sum2 float64
nx := len(x)
fnx := float64(nx)
s := 1 - (1 / ((2 * math.Sqrt(fnx+20)) - 8.2))
d := 1.0
mu0 := 2.5
mu1 := -math.Sqrt((math.Pow(mu0, 2) - d) / s)
xhat := make([]float64, nx)
xopt := newXopt(nx, mu0)
for i := range x {
xhat = append(xhat, 2*x[i])
if xopt[i] < 0 {
xhat[i] *= -1
}
}
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]
sum2 += (1 - math.Cos(2*math.Pi*zi))
}
return math.Min(sum0, (d*fnx)+(s*sum1)) + 10*sum2
}
// RosenbrockGriewank is the "Expanded Rosenbrock's plus Griewank's Function" // RosenbrockGriewank is the "Expanded Rosenbrock's plus Griewank's Function"
// of CEC2020. // of CEC2020.

@ -9,3 +9,8 @@ package cec2020
#define E 2.7182818284590452353602874713526625 #define E 2.7182818284590452353602874713526625
#define PI 3.1415926535897932384626433832795029 #define PI 3.1415926535897932384626433832795029
*/ */
const (
searchRangeMin = -100
searchRangeMax = 100
)

@ -3,7 +3,14 @@
package cec2020 package cec2020
import "math" import (
"math"
"time"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)
// void hf01 (double *, double *, int, double *,double *, int *,int, int); // Hybrid Function 1 // void hf01 (double *, double *, int, double *,double *, int *,int, int); // Hybrid Function 1
// void hf02 (double *, double *, int, double *,double *, int *,int, int); // Hybrid Function 2 // void hf02 (double *, double *, int, double *,double *, int *,int, int); // Hybrid Function 2
@ -112,3 +119,26 @@ func Asy(x []float64, beta float64) {
} }
} }
} }
func newXopt(n int, mu0 float64) []float64 {
gaussDist := &distuv.Uniform{
Src: rand.NewSource(uint64(time.Now().UnixNano())),
Min: searchRangeMin,
Max: searchRangeMax,
}
tmpvec := make([]float64, n)
xopt := make([]float64, n)
for i := 0; i < n; i++ {
tmpvec = append(tmpvec, gaussDist.Rand())
xopt = append(xopt, 0.5*mu0)
if tmpvec[i] < 0 {
xopt[i] *= -1
}
}
return xopt
}

@ -3,7 +3,14 @@
package cec2020 package cec2020
import "git.dotya.ml/wanderer/math-optim/bench"
/* /*
extern double *OShift,*M,*y,*z,*x_bound; extern double *OShift,*M,*y,*z,*x_bound;
extern int ini_flag,n_flag,func_flag,*SS; extern int ini_flag,n_flag,func_flag,*SS;
*/ */
var Functions = map[string]func([]float64) float64{}
// SearchRange specifies the CEC2020 search range.
var SearchRange = bench.NewfuncParams(searchRangeMin, searchRangeMax)