go(algo): seed prng once per algo run
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-07 17:55:47 +02:00
parent ab6dc7412e
commit e1fa0f08ff
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -48,18 +48,11 @@ func genValsRandomSearch(dimens uint, vals []float64, uniform *distuv.Uniform) {
// * dimens uint: number of dimensions of the objective function // * dimens uint: number of dimensions of the objective function
// * f func([]float64) float64: bench func to execute (see Functions map in // * f func([]float64) float64: bench func to execute (see Functions map in
// bench/functions.go) // bench/functions.go)
// * min/max float64: the upper/lower limit of the uniform distribution span, // * uniformDist distuv.Uniform: uniform distribution representation with
// which is relevant to the objective function. // the min/max bounds already set to function-specific limits.
func singleRandomSearch(dimens uint, f func([]float64) float64, min, max float64) ([]float64, float64) { func singleRandomSearch(dimens uint, f func([]float64) float64, uniformDist distuv.Uniform) ([]float64, float64) {
vals := make([]float64, dimens) vals := make([]float64, dimens)
// create a continuous uniform distribution representation within min/max bounds
uniformDist := distuv.Uniform{
Min: min,
Max: max,
Src: rand.NewSource(uint64(time.Now().UnixNano())),
}
genValsRandomSearch(dimens, vals, &uniformDist) genValsRandomSearch(dimens, vals, &uniformDist)
// result of the bench function. // result of the bench function.
@ -98,6 +91,14 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string) []s
localD = theD localD = theD
minIters = benchMinIters minIters = benchMinIters
// create a continuous uniform distribution representation.
uniformDist := &distuv.Uniform{
Src: rand.NewSource(uint64(
time.Now().
UnixNano(),
)),
}
// iterate over whatever was passed to us with theD - dimens slice. // iterate over whatever was passed to us with theD - dimens slice.
for _, dimens := range localD { for _, dimens := range localD {
randomSearchStatDimX := &stats.Stats{ randomSearchStatDimX := &stats.Stats{
@ -109,6 +110,10 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string) []s
funcStats := &stats.FuncStats{BenchName: benchFunc} funcStats := &stats.FuncStats{BenchName: benchFunc}
benchFuncParams := bench.FunctionParams[benchFunc] benchFuncParams := bench.FunctionParams[benchFunc]
// set min/max bounds.
uniformDist.Min = benchFuncParams.Min()
uniformDist.Max = benchFuncParams.Max()
printRandomSearch("running bench \"" + benchFunc + "\" for " + printRandomSearch("running bench \"" + benchFunc + "\" for " +
fmt.Sprint(randomSearchStatDimX.Dimens) + "D") fmt.Sprint(randomSearchStatDimX.Dimens) + "D")
@ -127,8 +132,7 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string) []s
_, r := singleRandomSearch( _, r := singleRandomSearch(
uint(dimens), uint(dimens),
bench.Functions[benchFunc], bench.Functions[benchFunc],
benchFuncParams.Min(), *uniformDist,
benchFuncParams.Max(),
) )
// is a switch efficient, or should an if statement be used..? // is a switch efficient, or should an if statement be used..?