diff --git a/algo/algo.go b/algo/algo.go index 966a972..2e64618 100644 --- a/algo/algo.go +++ b/algo/algo.go @@ -198,7 +198,12 @@ funcCount := len(bench.Functions) ch := make(chan []stats.Stats, funcCount) for i := range algoStats { - go HillClimb(10000, 30, bench.Dimensions, bench.FuncNames[i], ch) + // params: + // maxFES, benchMinIters, neighbours int, + // theD []int, + // benchFunc string, + // ch chan []stats.Stats + go HillClimb(10000, 30, 10, bench.Dimensions, bench.FuncNames[i], ch) } // get results. diff --git a/algo/plot.go b/algo/plot.go index eabbb99..084e87e 100644 --- a/algo/plot.go +++ b/algo/plot.go @@ -298,6 +298,7 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P log.Panic(err) } + // TODO(me): add Neighbourhood param filename := fmt.Sprintf("%s%s-%s-%s-%dD-%dG-%dI", picsDir, fPrefix, diff --git a/algo/stochasticHillClimbing.go b/algo/stochasticHillClimbing.go index 4706759..c4291c1 100644 --- a/algo/stochasticHillClimbing.go +++ b/algo/stochasticHillClimbing.go @@ -133,7 +133,12 @@ func genNeighbours(n, dimens int, benchName string, origin []float64, neighbVals } // singleHillClimb runs a single iteration of SHC. -func singleHillClimb(dimens uint, benchName string, oldVals []float64) ([]float64, float64) { +func singleHillClimb( + dimens uint, + neighbCount int, + benchName string, + oldVals []float64, +) ([]float64, float64) { neighbours := make([][]float64, dimens) // prealloc the slice the size of dimens (and oldVals, should be the same). vals := make([]float64, len(oldVals)) @@ -142,7 +147,7 @@ func singleHillClimb(dimens uint, benchName string, oldVals []float64) ([]float6 neighbours[i] = vals } - genNeighbours(bench.Neighbourhood, int(dimens), benchName, oldVals, neighbours) + genNeighbours(neighbCount, int(dimens), benchName, oldVals, neighbours) newVals, newRes := selectBestNeighbour(neighbours, benchName) @@ -152,7 +157,12 @@ func singleHillClimb(dimens uint, benchName string, oldVals []float64) ([]float6 // HillClimb performs 30 iterations of SHC (30 singleHillClimb func calls // internally) to establish a semi-relevant statistical baseline, and reports // the results of the computation. -func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan []stats.Stats) { +func HillClimb( + maxFES, benchMinIters, neighbours int, + theD []int, + benchFunc string, + ch chan []stats.Stats, +) { if maxFES <= 0 { } else if benchMinIters <= 0 { log.Fatalln(fmtSHCOut("benchMinIters cannot be <= 0, bailing")) @@ -183,7 +193,7 @@ func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan fes = maxFES // no need to call math.Floor() apparently, as `int()` does that implicitly. - fesPerIter = int(float64(fes / bench.Neighbourhood)) + fesPerIter = int(float64(fes / neighbours)) localD = theD minIters = benchMinIters @@ -209,15 +219,16 @@ funcStats := &stats.FuncStats{BenchName: benchFunc} Dimens: dimens, Iterations: minIters, Generations: fesPerIter, - Neighbours: bench.Neighbourhood, + Neighbours: neighbours, } uniDist := distuv.Uniform{ Min: benchFuncParams.Min(), Max: benchFuncParams.Max(), } - printSHC("running bench \"" + benchFunc + "\" for " + - fmt.Sprint(stochasticHCStatDimX.Dimens) + "D") + printSHC(fmt.Sprintf("running bench \"%s\" for %dD with %d Neighbours", + benchFunc, stochasticHCStatDimX.Dimens, neighbours), + ) funcStats.BenchResults = make([]stats.BenchRound, minIters) @@ -248,6 +259,7 @@ funcStats.BenchResults[iter].Iteration = iter if bV, bR := singleHillClimb( uint(dimens), + neighbours, benchFunc, initVals, ); bR != 0 { @@ -260,6 +272,7 @@ funcStats.BenchResults[iter].Iteration = iter for i := 0; i < fesPerIter; i++ { v, r := singleHillClimb( uint(dimens), + neighbours, benchFunc, bestVals, )