fix: clear up Hybrid funcs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-12 14:07:34 +01:00
parent 3933dc608a
commit 138e6f1d0b
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
3 changed files with 7 additions and 15 deletions

@ -81,13 +81,10 @@ func Hybrid1(x []float64) float64 {
p := []float64{0.3, 0.3, 0.4}
gnx := getGnx(p, fnx)
z := newOpt(nx)
mz := getMz(x, z)
var sum float64
for i := range funcs {
sum += funcs[i](mz) * gnx[i]
sum += funcs[i](x) * gnx[i]
}
return sum
@ -108,13 +105,10 @@ func Hybrid2(x []float64) float64 {
p := []float64{0.2, 0.2, 0.3, 0.3}
gnx := getGnx(p, fnx)
z := newOpt(nx)
mz := getMz(x, z)
var sum float64
for i := range funcs {
sum += funcs[i](mz) * gnx[i]
sum += funcs[i](x) * gnx[i]
}
return sum
@ -136,13 +130,10 @@ func Hybrid3(x []float64) float64 {
p := []float64{0.1, 0.2, 0.2, 0.2, 0.3}
gnx := getGnx(p, fnx)
z := newOpt(nx)
mz := getMz(x, z)
var sum float64
for i := range funcs {
sum += funcs[i](mz) * gnx[i]
sum += funcs[i](x) * gnx[i]
}
return sum

@ -51,7 +51,7 @@ func TestGriewank(t *testing.T) {
func TestHybrid1(t *testing.T) {
in := []float64{-9.2, 10, .7, 3, -80.2843}
want := 0.00025455132345086895
want := 2.0385039193698734e+08
got := Hybrid1(in)
@ -62,7 +62,7 @@ func TestHybrid1(t *testing.T) {
func TestHybrid2(t *testing.T) {
in := []float64{-9.2, 10, .7, 3, -80.2843}
want := 25.298615746321026
want := 4.6901057350488175e+06
got := Hybrid2(in)
@ -73,7 +73,7 @@ func TestHybrid2(t *testing.T) {
func TestHybrid3(t *testing.T) {
in := []float64{-9.2, 10, .7, 3, -80.2843}
want := 16.298615746321026
want := 2.0618485725498265e+08
got := Hybrid3(in)

@ -173,6 +173,7 @@ func getGnx(p []float64, fnx float64) []float64 {
}
// getMz calculates Mz.
// nolint: unused
func getMz(x []float64, z []float64) []float64 {
nx := len(x)
mz := make([]float64, nx)