go: rename AlgoMean,Mean et al.
All checks were successful
continuous-integration/drone/push Build is passing

also add comments to methods explaining what they're supposed to do.
This commit is contained in:
surtur 2022-07-25 22:24:54 +02:00
parent 9801554eb5
commit ea3d57acd8
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 33 additions and 23 deletions

@ -100,7 +100,10 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string, ch
)), )),
} }
rsMeans := &stats.AlgoMean{Algo: "Random Search"} rsMeans := &stats.AlgoBenchMean{
Algo: "Random Search",
BenchMeans: make([]stats.BenchMean, 0, len(localD)),
}
// iterate over whatever was passed to us with theD - dimens slice. // iterate over whatever was passed to us with theD - dimens slice.
for _, dimens := range localD { for _, dimens := range localD {
@ -112,7 +115,7 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string, ch
} }
funcStats := &stats.FuncStats{BenchName: benchFunc} funcStats := &stats.FuncStats{BenchName: benchFunc}
benchFuncParams := bench.FunctionParams[benchFunc] benchFuncParams := bench.FunctionParams[benchFunc]
dimXMean := &stats.Mean{ dimXMean := &stats.BenchMean{
Bench: benchFunc, Bench: benchFunc,
Dimens: dimens, Dimens: dimens,
Iterations: minIters, Iterations: minIters,
@ -182,7 +185,7 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string, ch
randomSearchStats = append(randomSearchStats, *randomSearchStatDimX) randomSearchStats = append(randomSearchStats, *randomSearchStatDimX)
// save to AlgoMeans // save to AlgoMeans
rsMeans.Means = append(rsMeans.Means, *dimXMean) rsMeans.BenchMeans = append(rsMeans.BenchMeans, *dimXMean)
} }
sort.Sort(rsMeans) sort.Sort(rsMeans)

@ -187,7 +187,10 @@ func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan
localD = theD localD = theD
minIters = benchMinIters minIters = benchMinIters
shcMeans := &stats.AlgoMean{Algo: "Stochastic Hill Climbing"} shcMeans := &stats.AlgoBenchMean{
Algo: "Stochastic Hill Climbing",
BenchMeans: make([]stats.BenchMean, 0, len(localD)),
}
for _, dimens := range localD { for _, dimens := range localD {
stochasticHCStatDimX := &stats.Stats{ stochasticHCStatDimX := &stats.Stats{
@ -201,7 +204,7 @@ func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan
} }
funcStats := &stats.FuncStats{BenchName: benchFunc} funcStats := &stats.FuncStats{BenchName: benchFunc}
benchFuncParams := bench.FunctionParams[benchFunc] benchFuncParams := bench.FunctionParams[benchFunc]
dimXMean := &stats.Mean{ dimXMean := &stats.BenchMean{
Bench: benchFunc, Bench: benchFunc,
Dimens: dimens, Dimens: dimens,
Iterations: minIters, Iterations: minIters,
@ -299,7 +302,7 @@ func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan
stochasticHCStats = append(stochasticHCStats, *stochasticHCStatDimX) stochasticHCStats = append(stochasticHCStats, *stochasticHCStatDimX)
// save to AlgoMeans. // save to AlgoMeans.
shcMeans.Means = append(shcMeans.Means, *dimXMean) shcMeans.BenchMeans = append(shcMeans.BenchMeans, *dimXMean)
} }
sort.Sort(shcMeans) sort.Sort(shcMeans)

@ -25,9 +25,9 @@ type FuncStats struct {
MeanVals []float64 MeanVals []float64
} }
// Mean structure holds mean vals and metadata of a specified // BenchMean structure holds mean vals and metadata of a bench-params
// bench-algo-settings combination. // combination.
type Mean struct { type BenchMean struct {
Bench string Bench string
Dimens int Dimens int
@ -40,15 +40,15 @@ type Mean struct {
MeanVals []float64 MeanVals []float64
} }
// AlgoMean holds Mean structs of different benchmarks but the same algorithm. // AlgoBenchMean holds BenchMean structs of different benchmarks but the same algorithm.
type AlgoMean struct { type AlgoBenchMean struct {
Algo string Algo string
Means []Mean BenchMeans []BenchMean
} }
// MeanStats aggregates AlgoMean structs of different algos. // MeanStats aggregates AlgoMean structs of different algos.
type MeanStats struct { type MeanStats struct {
AlgoMeans []AlgoMean AlgoMeans []AlgoBenchMean
} }
type Stats struct { type Stats struct {
@ -59,30 +59,34 @@ type Stats struct {
Generations int Generations int
} }
// the following three methods implement the sort.Interface. // Len implements the sort.Interface.
func (a AlgoMean) Len() int { func (a AlgoBenchMean) Len() int {
return len(a.Means) return len(a.BenchMeans)
} }
func (a AlgoMean) Less(i, j int) bool { // Less implements the sort.Interface.
return a.Means[i].Bench < a.Means[j].Bench func (a AlgoBenchMean) Less(i, j int) bool {
return a.BenchMeans[i].Bench < a.BenchMeans[j].Bench
} }
func (a AlgoMean) Swap(i, j int) { // Swap implements the sort.Interface.
a.Means[i], a.Means[j] = a.Means[j], a.Means[i] func (a AlgoBenchMean) Swap(i, j int) {
a.BenchMeans[i], a.BenchMeans[j] = a.BenchMeans[j], a.BenchMeans[i]
} }
// the following three methods also implement the sort.Interface. // Len implements the sort.Interface.
func (m MeanStats) Len() int { func (m MeanStats) Len() int {
return len(m.AlgoMeans) return len(m.AlgoMeans)
} }
// this in fact sorts in reverse (fits with our use case atm). // Less implements the sort.Interface.
// note: this in fact sorts in reverse (fits with our use case atm).
func (m MeanStats) Less(i, j int) bool { func (m MeanStats) Less(i, j int) bool {
// return m.AlgoMeans[i].Algo < m.AlgoMeans[j].Algo // return m.AlgoMeans[i].Algo < m.AlgoMeans[j].Algo
return m.AlgoMeans[i].Algo > m.AlgoMeans[j].Algo return m.AlgoMeans[i].Algo > m.AlgoMeans[j].Algo
} }
// Swap implements the sort.Interface.
func (m MeanStats) Swap(i, j int) { func (m MeanStats) Swap(i, j int) {
m.AlgoMeans[i], m.AlgoMeans[j] = m.AlgoMeans[j], m.AlgoMeans[i] m.AlgoMeans[i], m.AlgoMeans[j] = m.AlgoMeans[j], m.AlgoMeans[i]
} }