go: improve plotting for GAs
All checks were successful
continuous-integration/drone/push Build is passing

* handle special cases
* extend title, description
* set custom x axis description
This commit is contained in:
leo 2023-01-21 02:45:56 +01:00
parent b742f0e091
commit cffbcd9866
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
3 changed files with 33 additions and 5 deletions

View File

@ -155,6 +155,9 @@ func (j *JDE) Run() {
Dimens: dim,
Iterations: j.BenchMinIters,
Generations: maxFES,
NP: j.NP,
F: j.F,
CR: j.CR,
}
funcStats := &stats.FuncStats{BenchName: j.BenchName}
dimXMean := &stats.BenchMean{

View File

@ -6,6 +6,7 @@
import (
"fmt"
"log"
"strconv"
"strings"
"sync"
"time"
@ -23,7 +24,7 @@
const (
preferredFont = "Mono"
titlePreferredFont = "Sans"
yAxisLabel = "CF value"
yAxisLabel = "f(x)"
xAxisLabel = "Generations"
)
@ -246,6 +247,14 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P
s.Generations,
s.Iterations,
)
// For differential evolution, add params to title.
if strings.Contains(s.Algo, "DE") {
p.Title.Text += fmt.Sprintf(",\nNP: %d, F: ", s.NP) +
strconv.FormatFloat(s.F, 'f', -1, 64) + ", CR: " +
strconv.FormatFloat(s.CR, 'f', -1, 64)
}
// this is latex-rendered.
pic.Caption = strings.ReplaceAll(p.Title.Text, " ", "~")
@ -254,7 +263,12 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P
pL.Bench = s.BenchFuncStats[0].BenchName
pLMean.Bench = s.BenchFuncStats[0].BenchName
p.X.Label.Text = xAxisLabel
if strings.Contains(s.Algo, "DE") {
p.X.Label.Text = "FES"
} else {
p.X.Label.Text = xAxisLabel
}
p.X.Label.TextStyle.Font.Variant = preferredFont
p.X.Label.TextStyle.Font.Weight = 1 // Medium
p.X.Tick.Label.Font.Variant = preferredFont
@ -350,11 +364,15 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P
filename, fExt, elapsed,
)
// TODO(me): rework this.
if s.Algo == "Random Search" {
switch {
case s.Algo == "Random Search":
printRandomSearch(info)
} else {
case strings.Contains(s.Algo, "Stochastic Hill Climbing"):
printSHC(info)
default:
log.Println(info)
}
// Save the plot to a file using the above-constructed 'filename'.

View File

@ -67,6 +67,13 @@ type Stats struct {
// comparing than algo generations, which can vary based on the type of
// algo, number of neighbours, etc..
Generations int
// NP is the initial population size, disable with 0. Only applicable to
// GAs (see algo/de for more details).
NP int
// F is the mutation factor, disable with 0. Only applicable to GAs.
F float64
// CR is the crossover probability, disable with 0. Only applicable to GAs.
CR float64
}
// Len implements the sort.Interface.