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

This commit is contained in:
leo 2023-02-08 02:06:28 +01:00
parent a9135c535f
commit ba8ccf305b
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 49 additions and 1 deletions

@ -184,7 +184,44 @@ func Hybrid3(x []float64) float64 {
} }
// Composition1 is the "Composition Function 1" of CEC2020. // Composition1 is the "Composition Function 1" of CEC2020.
func Composition1(x []float64) float64 { return 0 } func Composition1(x []float64) float64 {
nx := len(x)
fnx := float64(nx)
// optimum positions.
o := newOpt(nx)
sigma := []float64{10, 20, 30}
lambda := []float64{1, 10, 1}
bias := []float64{0, 100, 200}
omega := make([]float64, nx)
funcs := []func([]float64) float64{
Rastrigin,
Griewank,
SchwefelModified,
}
var sum float64
var weights []float64
for i := range funcs {
wi := getWeight(x, o, sigma[i], fnx)
weights = append(weights, wi)
var wsum float64
for j := range weights {
wsum += weights[j]
}
omega = append(omega, wi/wsum)
sum += (omega[i] * (lambda[i]*funcs[i](x) + bias[i])) + funcs[i](x)
}
return sum
}
// Composition2 is the "Composition Function 2" of CEC2020. // Composition2 is the "Composition Function 2" of CEC2020.
func Composition2(x []float64) float64 { return 0 } func Composition2(x []float64) float64 { return 0 }

@ -191,3 +191,14 @@ func getMz(x []float64, z []float64) []float64 {
return mz return mz
} }
func getWeight(x, o []float64, sigma, nx float64) float64 {
var sum float64
for i := range x {
sum += math.Pow(x[i]-o[i], 2)
}
// w.
return (1 / (math.Sqrt(sum))) * math.Exp(-(sum / 2 * nx * math.Pow(sigma, 2)))
}