go: implement RandomSearch wip2
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* perform RandomSearch with each of the benchmarking functions for a
prescribed number of iterations
left to do:
* saving the solution
* parsing the solution to a table
* parsing the solution to generate graphs
* follow-up of b3787da640
This commit is contained in:
parent
f1b3c1c90f
commit
cbf47031f9
|
@ -46,7 +46,6 @@ func genValsRandomSearch(dimens uint, vals []float64, uniform *distuv.Uniform) {
|
|||
// * f string: name of the bench func to optimise (see bench/functions)
|
||||
// * min/max float64: the upper/lower limit of the uniform distribution span,
|
||||
// which is relevant to the objective function.
|
||||
// nolint
|
||||
func singleRandomSearch(dimens uint, f string, min, max float64) ([]float64, float64) {
|
||||
vals := make([]float64, dimens)
|
||||
|
||||
|
@ -73,6 +72,8 @@ func singleRandomSearch(dimens uint, f string, min, max float64) ([]float64, flo
|
|||
return vals, res
|
||||
}
|
||||
|
||||
// TODO(me): split this up
|
||||
// nolint: gocognit
|
||||
func RandomSearch(fes uint) {
|
||||
if fes == 0 {
|
||||
log.Fatalln(" random search: fes set to 0, bailing")
|
||||
|
@ -90,47 +91,93 @@ func RandomSearch(fes uint) {
|
|||
|
||||
var resultsDeJong2nd Values
|
||||
|
||||
var bestResultsSchwefel []float64
|
||||
|
||||
var bestResultsDeJong1st []float64
|
||||
|
||||
var bestResultsDeJong2nd []float64
|
||||
|
||||
// iterations needed to establish a minimal viable statistical baseline
|
||||
minIters := 30
|
||||
|
||||
for _, dimens := range bench.Dimensions {
|
||||
for i := 0; i < minIters; i++ {
|
||||
// run Schwefel.
|
||||
v, r := singleRandomSearch(
|
||||
dimens,
|
||||
bench.Functions[0],
|
||||
bench.SchwefelParams.Min(),
|
||||
bench.SchwefelParams.Max(),
|
||||
)
|
||||
valsSchwefel = append(valsSchwefel, v)
|
||||
resultsSchwefel = append(resultsSchwefel, r)
|
||||
var bestResult float64
|
||||
|
||||
// run De Jong 1st.
|
||||
vDJ1, rDJ1 := singleRandomSearch(
|
||||
dimens,
|
||||
bench.Functions[1],
|
||||
bench.DeJong1Params.Min(),
|
||||
bench.DeJong1Params.Max(),
|
||||
)
|
||||
valsDeJong1st = append(valsDeJong1st, vDJ1)
|
||||
resultsDeJong1st = append(resultsDeJong1st, rDJ1)
|
||||
// run De Jong 2nd.
|
||||
vDJ2, rDJ2 := singleRandomSearch(
|
||||
dimens,
|
||||
bench.Functions[2],
|
||||
bench.DeJong2Params.Min(),
|
||||
bench.DeJong2Params.Max(),
|
||||
)
|
||||
valsDeJong2nd = append(valsDeJong2nd, vDJ2)
|
||||
resultsDeJong2nd = append(resultsDeJong2nd, rDJ2)
|
||||
for j := 0; j < int(fes); j++ {
|
||||
// run Schwefel.
|
||||
v, r := singleRandomSearch(
|
||||
dimens,
|
||||
bench.Functions[0],
|
||||
bench.SchwefelParams.Min(),
|
||||
bench.SchwefelParams.Max(),
|
||||
)
|
||||
valsSchwefel = append(valsSchwefel, v)
|
||||
resultsSchwefel = append(resultsSchwefel, r)
|
||||
|
||||
switch j {
|
||||
// first iteration
|
||||
case 0:
|
||||
bestResult = r
|
||||
default:
|
||||
// any other than the first iteration and a better solution
|
||||
if r < bestResult {
|
||||
bestResult = r
|
||||
}
|
||||
}
|
||||
|
||||
bestResultsSchwefel = append(bestResultsSchwefel, bestResult)
|
||||
}
|
||||
|
||||
for k := 0; k < int(fes); k++ {
|
||||
// run De Jong 1st.
|
||||
v, r := singleRandomSearch(
|
||||
dimens,
|
||||
bench.Functions[1],
|
||||
bench.DeJong1Params.Min(),
|
||||
bench.DeJong1Params.Max(),
|
||||
)
|
||||
valsDeJong1st = append(valsDeJong1st, v)
|
||||
resultsDeJong1st = append(resultsDeJong1st, r)
|
||||
|
||||
// first iteration or better solution
|
||||
if k == 0 || r < bestResult {
|
||||
bestResult = r
|
||||
}
|
||||
|
||||
bestResultsDeJong1st = append(bestResultsDeJong1st, bestResult)
|
||||
}
|
||||
|
||||
for l := 0; l < int(fes); l++ {
|
||||
// run De Jong 2nd.
|
||||
v, r := singleRandomSearch(
|
||||
dimens,
|
||||
bench.Functions[2],
|
||||
bench.DeJong2Params.Min(),
|
||||
bench.DeJong2Params.Max(),
|
||||
)
|
||||
valsDeJong2nd = append(valsDeJong2nd, v)
|
||||
resultsDeJong2nd = append(resultsDeJong2nd, r)
|
||||
|
||||
// first iteration or better solution
|
||||
if l == 0 || r < bestResult {
|
||||
bestResult = r
|
||||
}
|
||||
|
||||
bestResultsDeJong2nd = append(bestResultsDeJong2nd, bestResult)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr, "vals schw:", valsSchwefel)
|
||||
fmt.Fprintln(os.Stderr, "vals dj1", valsDeJong1st)
|
||||
fmt.Fprintln(os.Stderr, "vals dj2", valsDeJong2nd)
|
||||
fmt.Fprintln(os.Stderr, "vals schw len", len(valsSchwefel))
|
||||
fmt.Fprintln(os.Stderr, "vals dj1 len", len(valsDeJong1st))
|
||||
fmt.Fprintln(os.Stderr, "vals dj2 len", len(valsDeJong2nd))
|
||||
|
||||
fmt.Fprintln(os.Stderr, "res schw:", resultsSchwefel)
|
||||
fmt.Fprintln(os.Stderr, "res dj1", resultsDeJong1st)
|
||||
fmt.Fprintln(os.Stderr, "res dj2", resultsDeJong2nd)
|
||||
fmt.Fprintln(os.Stderr, "res schw len", len(resultsSchwefel))
|
||||
fmt.Fprintln(os.Stderr, "res dj1 len", len(resultsDeJong1st))
|
||||
fmt.Fprintln(os.Stderr, "res dj2 len", len(resultsDeJong2nd))
|
||||
|
||||
fmt.Fprintln(os.Stderr, "best res schw len", len(bestResultsSchwefel))
|
||||
fmt.Fprintln(os.Stderr, "best res dj1 len", len(bestResultsDeJong1st))
|
||||
fmt.Fprintln(os.Stderr, "best res dj2 len", len(bestResultsDeJong2nd))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue