From 7c8c17007a72b19b4f0f2bc03025de1dadda4baa Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 8 Feb 2023 02:11:16 +0100 Subject: [PATCH] cec2020: implement Composition3 func --- bench/cec2020/benchFunctions.go | 41 ++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/bench/cec2020/benchFunctions.go b/bench/cec2020/benchFunctions.go index 70086dd..5b92e92 100644 --- a/bench/cec2020/benchFunctions.go +++ b/bench/cec2020/benchFunctions.go @@ -265,4 +265,43 @@ func Composition2(x []float64) float64 { } // Composition3 is the "Composition Function 3" of CEC2020. -func Composition3(x []float64) float64 { return 0 } +func Composition3(x []float64) float64 { + nx := len(x) + fnx := float64(nx) + + // optimum positions. + o := newOpt(nx) + sigma := []float64{10, 20, 30, 40, 50} + lambda := []float64{10, 1, 10, 1e-6, 1} + bias := []float64{0, 100, 200, 300, 400} + omega := make([]float64, nx) + funcs := []func([]float64) float64{ + Rastrigin, + Happycat, + Ackley, + Discus, + Rosenbrock, + } + + 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 +}