From c37ef263ae22600738847062a0ba4d1a5e998002 Mon Sep 17 00:00:00 2001 From: surtur Date: Tue, 19 Jul 2022 19:58:45 +0200 Subject: [PATCH] go(stats): Solution -> BenchResults in FuncStats --- algo/plot.go | 6 +++--- algo/randomSearch.go | 8 ++++---- algo/stochasticHillClimbing.go | 8 ++++---- stats/stats.go | 10 +++++----- stats/table.go | 2 +- stats/table_test.go | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/algo/plot.go b/algo/plot.go index 3f9f431..ede1ee6 100644 --- a/algo/plot.go +++ b/algo/plot.go @@ -136,7 +136,7 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P // https://stackoverflow.com/a/44872993 lines := make([]interface{}, 0) - for _, iter := range dim.Solution { + for _, iter := range dim.BenchResults { // mark the end of the X axis with len(iter.Results). p.X.Max = float64(len(iter.Results)) @@ -174,7 +174,7 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P util.SanitiseFName(dim.BenchName) + "-" + fmt.Sprint(s.Dimens) + "D-" + fmt.Sprint(s.Generations) + "G-" + - fmt.Sprint(len(dim.Solution)) + "I" + fmt.Sprint(len(dim.BenchResults)) + "I" filenameMean := filename + util.SanitiseFName(" Mean") // NEVER EVER ATTEMPT TO INITIALISE THIS WITH `pic`! @@ -190,7 +190,7 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P picMean.FilePath = filenameMean // get the *mean* plot. - pMean := plotMeanVals(dim.Solution, meanTitle, s.Generations) + pMean := plotMeanVals(dim.BenchResults, meanTitle, s.Generations) elapsed := time.Since(start) info := "saving img to file: " + filename + "(-Mean)" + fExt + diff --git a/algo/randomSearch.go b/algo/randomSearch.go index 98a2609..82a2a8e 100644 --- a/algo/randomSearch.go +++ b/algo/randomSearch.go @@ -117,7 +117,7 @@ funcStats := &stats.FuncStats{BenchName: benchFunc} printRandomSearch("running bench \"" + benchFunc + "\" for " + fmt.Sprint(randomSearchStatDimX.Dimens) + "D") - funcStats.Solution = make([]stats.BenchRound, minIters) + funcStats.BenchResults = make([]stats.BenchRound, minIters) // perform the while dance 'minIters' times for "statistical relevance" for iter := 0; iter < minIters; iter++ { @@ -125,7 +125,7 @@ funcStats.Solution = make([]stats.BenchRound, minIters) var bestResult float64 // set current iteration in funcStats. - funcStats.Solution[iter].Iteration = iter + funcStats.BenchResults[iter].Iteration = iter // run the benchmarking function 'fes' times. for i := 0; i < fes; i++ { @@ -149,8 +149,8 @@ funcStats.Solution[iter].Iteration = iter } // save the 'best' result, since we only care about those. - funcStats.Solution[iter].Results = append( - funcStats.Solution[iter].Results, + funcStats.BenchResults[iter].Results = append( + funcStats.BenchResults[iter].Results, bestResult, ) } diff --git a/algo/stochasticHillClimbing.go b/algo/stochasticHillClimbing.go index f2defd0..82c0cba 100644 --- a/algo/stochasticHillClimbing.go +++ b/algo/stochasticHillClimbing.go @@ -206,7 +206,7 @@ funcStats := &stats.FuncStats{BenchName: benchFunc} printSHC("running bench \"" + benchFunc + "\" for " + fmt.Sprint(stochasticHCStatDimX.Dimens) + "D") - funcStats.Solution = make([]stats.BenchRound, minIters) + funcStats.BenchResults = make([]stats.BenchRound, minIters) // create a source of preudo-randomness. src := rand.NewSource(uint64(rand.Int63())) @@ -216,7 +216,7 @@ funcStats.Solution = make([]stats.BenchRound, minIters) start := time.Now() for iter := 0; iter < minIters; iter++ { - funcStats.Solution[iter].Iteration = iter + funcStats.BenchResults[iter].Iteration = iter // create and stochastically populate the vals slice. initVals := make([]float64, dimens) @@ -263,8 +263,8 @@ funcStats.Solution[iter].Iteration = iter } } - funcStats.Solution[iter].Results = append( - funcStats.Solution[iter].Results, + funcStats.BenchResults[iter].Results = append( + funcStats.BenchResults[iter].Results, bestResult, ) } diff --git a/stats/stats.go b/stats/stats.go index a641376..e28e90c 100644 --- a/stats/stats.go +++ b/stats/stats.go @@ -19,8 +19,8 @@ type BenchRound struct { } type FuncStats struct { - BenchName string - Solution []BenchRound + BenchName string + BenchResults []BenchRound } type Stats struct { @@ -31,10 +31,10 @@ type Stats struct { Generations int } -func GetFuncStats(funcName string, solution []BenchRound) FuncStats { +func GetFuncStats(funcName string, benchResults []BenchRound) FuncStats { f := FuncStats{ - BenchName: funcName, - Solution: solution, + BenchName: funcName, + BenchResults: benchResults, } return f diff --git a/stats/table.go b/stats/table.go index 602cb73..e546dd0 100644 --- a/stats/table.go +++ b/stats/table.go @@ -69,7 +69,7 @@ func parseSingleBenchStats(benchStats []Stats) []report.Row { // collect the best. var best []float64 - for _, iter := range dim.Solution { + for _, iter := range dim.BenchResults { last := s.Generations - 1 best = append(best, iter.Results[last]) diff --git a/stats/table_test.go b/stats/table_test.go index ccfcc9c..3620d45 100644 --- a/stats/table_test.go +++ b/stats/table_test.go @@ -22,7 +22,7 @@ func TestParseBenchStats(t *testing.T) { benchFuncStats := []FuncStats{ { BenchName: "De Jong 5th", - Solution: []BenchRound{ + BenchResults: []BenchRound{ {Iteration: 0, Results: []float64{2803.7015205977887, 2296.736381649773, 1763.9319525203364}}, {Iteration: 1, Results: []float64{2169.7378893600176, 2169.7378893600176, 2169.7378893600176}}, {Iteration: 2, Results: []float64{1909.6488355929007, 1336.3261400058473, 1336.3261400058473}},