cec2020: generalise Hybrid1 func's internals
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-08 01:11:20 +01:00
parent 0521525e1f
commit e34922d6e5
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 40 additions and 23 deletions

@ -107,35 +107,25 @@ func Hybrid1(x []float64) float64 {
nx := len(x)
fnx := float64(nx)
f1 := SchwefelModified
f2 := Rastrigin
f3 := HighConditionedElliptic
// percentages.
p := []float64{0.3, 0.3, 0.4}
gnx := make([]float64, len(p))
gnxsum := 0.0
for i := 0; i < len(p)-1; i++ {
gnx[i] = math.Ceil(p[i] * fnx)
gnxsum += gnx[i]
funcs := []func([]float64) float64{
SchwefelModified,
Rastrigin,
HighConditionedElliptic,
}
gnx[len(p)] = fnx - gnxsum
// percentages used to control the amount of contribution of each func.
p := []float64{0.3, 0.3, 0.4}
gnx := getGnx(p, fnx)
z := newOpt(nx)
mz := make([]float64, nx)
mz := getMz(x, z)
for i := range x {
mz = append(mz, x[i]*z[i])
var sum float64
for i := range funcs {
sum += funcs[i](mz) * gnx[i]
}
// results.
r1 := f1(mz)
r2 := f2(mz)
r3 := f3(mz)
return gnx[0]*r1 + gnx[1]*r2 + gnx[2]*r3
return sum
}
// Hybrid2 is the "Hybrid Function 2" of CEC2020.

@ -164,3 +164,30 @@ func newOpt(n int) []float64 {
return xopt
}
// getGnx calculates G_nx.
func getGnx(p []float64, fnx float64) []float64 {
gnx := make([]float64, len(p))
gnxsum := 0.0
for i := 0; i < len(p)-1; i++ {
gnx[i] = math.Ceil(p[i] * fnx)
gnxsum += gnx[i]
}
gnx[len(p)] = fnx - gnxsum
return gnx
}
// getMz calculates Mz.
func getMz(x []float64, z []float64) []float64 {
nx := len(x)
mz := make([]float64, nx)
for i := range x {
mz = append(mz, x[i]*z[i])
}
return mz
}