go: allow modifying HillClimb's 'neighbours' param
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a9dfe4cc6b
commit
c4077a449d
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue