go: improve plotting for GAs
All checks were successful
continuous-integration/drone/push Build is passing
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:
parent
b742f0e091
commit
cffbcd9866
@ -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{
|
||||
|
26
algo/plot.go
26
algo/plot.go
@ -6,6 +6,7 @@ package algo
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -23,7 +24,7 @@ import (
|
||||
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
|
||||
|
||||
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'.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user