fix(go): collect and plot algo stats comparably
All checks were successful
continuous-integration/drone/push Build is passing

...i.e. based on FES, not Generations.
This commit is contained in:
surtur 2022-08-20 23:28:30 +02:00
parent 1793f7bdd9
commit 1ce3a6d04f
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 26 additions and 8 deletions

@ -55,7 +55,7 @@ func PlotMeanValsMulti(
iterations, bench, dimens, iterations, bench, dimens,
) )
p.X.Label.Text = xAxisLabel p.X.Label.Text = "Objective func. evaluations"
p.X.Label.TextStyle.Font.Variant = preferredFont p.X.Label.TextStyle.Font.Variant = preferredFont
p.X.Label.TextStyle.Font.Weight = 1 // Medium p.X.Label.TextStyle.Font.Weight = 1 // Medium
p.X.Tick.Label.Font.Variant = preferredFont p.X.Tick.Label.Font.Variant = preferredFont

@ -157,6 +157,7 @@ func singleHillClimb(
// HillClimb performs 30 iterations of SHC (30 singleHillClimb func calls // HillClimb performs 30 iterations of SHC (30 singleHillClimb func calls
// internally) to establish a semi-relevant statistical baseline, and reports // internally) to establish a semi-relevant statistical baseline, and reports
// the results of the computation. // the results of the computation.
// nolint: gocognit
func HillClimb( func HillClimb(
maxFES, benchMinIters, neighbours int, maxFES, benchMinIters, neighbours int,
theD []int, theD []int,
@ -207,10 +208,9 @@ func HillClimb(
Algo: "Stochastic Hill Climbing", Algo: "Stochastic Hill Climbing",
Dimens: dimens, Dimens: dimens,
Iterations: minIters, Iterations: minIters,
// Generations for Stochastic Hill Climbing may vary based on both // this is subject to change, see note on Stats struct in pkg
// the maxFES and bench.Neighbourhood, since that is how we arrive // stats.
// at the value of fesPerIter. Generations: fes,
Generations: fesPerIter,
} }
funcStats := &stats.FuncStats{BenchName: benchFunc} funcStats := &stats.FuncStats{BenchName: benchFunc}
benchFuncParams := bench.FunctionParams[benchFunc] benchFuncParams := bench.FunctionParams[benchFunc]
@ -218,7 +218,7 @@ func HillClimb(
Bench: benchFunc, Bench: benchFunc,
Dimens: dimens, Dimens: dimens,
Iterations: minIters, Iterations: minIters,
Generations: fesPerIter, Generations: fes,
Neighbours: neighbours, Neighbours: neighbours,
} }
uniDist := distuv.Uniform{ uniDist := distuv.Uniform{
@ -293,6 +293,21 @@ func HillClimb(
funcStats.BenchResults[iter].Results, funcStats.BenchResults[iter].Results,
bestResult, bestResult,
) )
// this block makes sure we properly count func evaluations for
// the purpose of correctly comparable plot comparison. i.e.
// append the winning (current best) value neighbours-1 (the
// first best is already saved at this point) times to
// represent the fact that while evaluating the neighbours to
// the current best value is taking place in the background,
// the current best value itself is kept around and
// symbolically saved as the best of the Generation.
for x := 0; x < neighbours-1; x++ {
funcStats.BenchResults[iter].Results = append(
funcStats.BenchResults[iter].Results,
bestResult,
)
}
} }
} }
@ -303,7 +318,7 @@ func HillClimb(
) )
// get mean vals. // get mean vals.
dimXMean.MeanVals = stats.GetMeanVals(funcStats.BenchResults, fesPerIter) dimXMean.MeanVals = stats.GetMeanVals(funcStats.BenchResults, fes)
// save to funcStats, too. // save to funcStats, too.
funcStats.MeanVals = dimXMean.MeanVals funcStats.MeanVals = dimXMean.MeanVals

@ -63,7 +63,10 @@ type Stats struct {
Dimens int Dimens int
BenchFuncStats []FuncStats BenchFuncStats []FuncStats
Iterations int Iterations int
Generations int // this should perhaps be named FES as that is a smarter thing to be
// comparing than algo generations, which can vary based on the type of
// algo, number of neighbours, etc..
Generations int
} }
// Len implements the sort.Interface. // Len implements the sort.Interface.