cec2020: implement Composition1 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
a9135c535f
commit
ba8ccf305b
@ -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)))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user