diff --git a/algo/randomSearch.go b/algo/randomSearch.go index e12fa5c..d8181de 100644 --- a/algo/randomSearch.go +++ b/algo/randomSearch.go @@ -48,18 +48,11 @@ func genValsRandomSearch(dimens uint, vals []float64, uniform *distuv.Uniform) { // * dimens uint: number of dimensions of the objective function // * f func([]float64) float64: bench func to execute (see Functions map in // bench/functions.go) -// * min/max float64: the upper/lower limit of the uniform distribution span, -// which is relevant to the objective function. -func singleRandomSearch(dimens uint, f func([]float64) float64, min, max float64) ([]float64, float64) { +// * uniformDist distuv.Uniform: uniform distribution representation with +// the min/max bounds already set to function-specific limits. +func singleRandomSearch(dimens uint, f func([]float64) float64, uniformDist distuv.Uniform) ([]float64, float64) { 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) // result of the bench function. @@ -98,6 +91,14 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string) []s localD = theD 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. for _, dimens := range localD { randomSearchStatDimX := &stats.Stats{ @@ -109,6 +110,10 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string) []s funcStats := &stats.FuncStats{BenchName: benchFunc} benchFuncParams := bench.FunctionParams[benchFunc] + // set min/max bounds. + uniformDist.Min = benchFuncParams.Min() + uniformDist.Max = benchFuncParams.Max() + printRandomSearch("running bench \"" + benchFunc + "\" for " + fmt.Sprint(randomSearchStatDimX.Dimens) + "D") @@ -127,8 +132,7 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string) []s _, r := singleRandomSearch( uint(dimens), bench.Functions[benchFunc], - benchFuncParams.Min(), - benchFuncParams.Max(), + *uniformDist, ) // is a switch efficient, or should an if statement be used..?