go: rename AlgoMean,Mean et al.
All checks were successful
continuous-integration/drone/push Build is passing
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:
parent
9801554eb5
commit
ea3d57acd8
@ -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.
|
||||
for _, dimens := range localD {
|
||||
@ -112,7 +115,7 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string, ch
|
||||
}
|
||||
funcStats := &stats.FuncStats{BenchName: benchFunc}
|
||||
benchFuncParams := bench.FunctionParams[benchFunc]
|
||||
dimXMean := &stats.Mean{
|
||||
dimXMean := &stats.BenchMean{
|
||||
Bench: benchFunc,
|
||||
Dimens: dimens,
|
||||
Iterations: minIters,
|
||||
@ -182,7 +185,7 @@ func RandomSearchNG(maxFES, benchMinIters int, theD []int, benchFunc string, ch
|
||||
randomSearchStats = append(randomSearchStats, *randomSearchStatDimX)
|
||||
|
||||
// save to AlgoMeans
|
||||
rsMeans.Means = append(rsMeans.Means, *dimXMean)
|
||||
rsMeans.BenchMeans = append(rsMeans.BenchMeans, *dimXMean)
|
||||
}
|
||||
|
||||
sort.Sort(rsMeans)
|
||||
|
@ -187,7 +187,10 @@ func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan
|
||||
localD = theD
|
||||
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 {
|
||||
stochasticHCStatDimX := &stats.Stats{
|
||||
@ -201,7 +204,7 @@ func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan
|
||||
}
|
||||
funcStats := &stats.FuncStats{BenchName: benchFunc}
|
||||
benchFuncParams := bench.FunctionParams[benchFunc]
|
||||
dimXMean := &stats.Mean{
|
||||
dimXMean := &stats.BenchMean{
|
||||
Bench: benchFunc,
|
||||
Dimens: dimens,
|
||||
Iterations: minIters,
|
||||
@ -299,7 +302,7 @@ func HillClimb(maxFES, benchMinIters int, theD []int, benchFunc string, ch chan
|
||||
stochasticHCStats = append(stochasticHCStats, *stochasticHCStatDimX)
|
||||
|
||||
// save to AlgoMeans.
|
||||
shcMeans.Means = append(shcMeans.Means, *dimXMean)
|
||||
shcMeans.BenchMeans = append(shcMeans.BenchMeans, *dimXMean)
|
||||
}
|
||||
|
||||
sort.Sort(shcMeans)
|
||||
|
@ -25,9 +25,9 @@ type FuncStats struct {
|
||||
MeanVals []float64
|
||||
}
|
||||
|
||||
// Mean structure holds mean vals and metadata of a specified
|
||||
// bench-algo-settings combination.
|
||||
type Mean struct {
|
||||
// BenchMean structure holds mean vals and metadata of a bench-params
|
||||
// combination.
|
||||
type BenchMean struct {
|
||||
Bench string
|
||||
Dimens int
|
||||
|
||||
@ -40,15 +40,15 @@ type Mean struct {
|
||||
MeanVals []float64
|
||||
}
|
||||
|
||||
// AlgoMean holds Mean structs of different benchmarks but the same algorithm.
|
||||
type AlgoMean struct {
|
||||
// AlgoBenchMean holds BenchMean structs of different benchmarks but the same algorithm.
|
||||
type AlgoBenchMean struct {
|
||||
Algo string
|
||||
Means []Mean
|
||||
BenchMeans []BenchMean
|
||||
}
|
||||
|
||||
// MeanStats aggregates AlgoMean structs of different algos.
|
||||
type MeanStats struct {
|
||||
AlgoMeans []AlgoMean
|
||||
AlgoMeans []AlgoBenchMean
|
||||
}
|
||||
|
||||
type Stats struct {
|
||||
@ -59,30 +59,34 @@ type Stats struct {
|
||||
Generations int
|
||||
}
|
||||
|
||||
// the following three methods implement the sort.Interface.
|
||||
func (a AlgoMean) Len() int {
|
||||
return len(a.Means)
|
||||
// Len implements the sort.Interface.
|
||||
func (a AlgoBenchMean) Len() int {
|
||||
return len(a.BenchMeans)
|
||||
}
|
||||
|
||||
func (a AlgoMean) Less(i, j int) bool {
|
||||
return a.Means[i].Bench < a.Means[j].Bench
|
||||
// Less implements the sort.Interface.
|
||||
func (a AlgoBenchMean) Less(i, j int) bool {
|
||||
return a.BenchMeans[i].Bench < a.BenchMeans[j].Bench
|
||||
}
|
||||
|
||||
func (a AlgoMean) Swap(i, j int) {
|
||||
a.Means[i], a.Means[j] = a.Means[j], a.Means[i]
|
||||
// Swap implements the sort.Interface.
|
||||
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 {
|
||||
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 {
|
||||
// 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) {
|
||||
m.AlgoMeans[i], m.AlgoMeans[j] = m.AlgoMeans[j], m.AlgoMeans[i]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user