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

View File

@ -55,7 +55,7 @@ func PlotMeanValsMulti(
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.Weight = 1 // Medium
p.X.Tick.Label.Font.Variant = preferredFont

View File

@ -157,6 +157,7 @@ func singleHillClimb(
// 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.
// nolint: gocognit
func HillClimb(
maxFES, benchMinIters, neighbours int,
theD []int,
@ -207,10 +208,9 @@ func HillClimb(
Algo: "Stochastic Hill Climbing",
Dimens: dimens,
Iterations: minIters,
// Generations for Stochastic Hill Climbing may vary based on both
// the maxFES and bench.Neighbourhood, since that is how we arrive
// at the value of fesPerIter.
Generations: fesPerIter,
// this is subject to change, see note on Stats struct in pkg
// stats.
Generations: fes,
}
funcStats := &stats.FuncStats{BenchName: benchFunc}
benchFuncParams := bench.FunctionParams[benchFunc]
@ -218,7 +218,7 @@ funcStats := &stats.FuncStats{BenchName: benchFunc}
Bench: benchFunc,
Dimens: dimens,
Iterations: minIters,
Generations: fesPerIter,
Generations: fes,
Neighbours: neighbours,
}
uniDist := distuv.Uniform{
@ -293,6 +293,21 @@ funcStats.BenchResults[iter].Results = append(
funcStats.BenchResults[iter].Results,
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 @@ funcStats.BenchResults[iter].Results,
)
// get mean vals.
dimXMean.MeanVals = stats.GetMeanVals(funcStats.BenchResults, fesPerIter)
dimXMean.MeanVals = stats.GetMeanVals(funcStats.BenchResults, fes)
// save to funcStats, too.
funcStats.MeanVals = dimXMean.MeanVals

View File

@ -63,7 +63,10 @@ type Stats struct {
Dimens int
BenchFuncStats []FuncStats
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.