go(algo): add DojDE()
All checks were successful
continuous-integration/drone/push Build is passing

the implementation is a WIP.

adjust linter ignoring in algo/plot.go: unparam does not like that
fPrefix is "plot" each time the func is called. this might get reworked
later.

also add field from bench/bench.go - DimensionsGA - Genetic Algorithm
specific dimensions.
This commit is contained in:
leo 2023-01-19 20:11:22 +01:00
parent 93dc845fbb
commit 7e358b01af
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
3 changed files with 77 additions and 2 deletions

@ -9,6 +9,7 @@ import (
"sort"
"sync"
"git.dotya.ml/wanderer/math-optim/algo/de"
"git.dotya.ml/wanderer/math-optim/bench"
"git.dotya.ml/wanderer/math-optim/report"
"git.dotya.ml/wanderer/math-optim/stats"
@ -325,3 +326,74 @@ func DoStochasticHillClimbing100Neigh(wg *sync.WaitGroup, m *sync.Mutex) {
stats.SaveTable(algoName, algoStats)
m.Unlock()
}
func DojDE(wg *sync.WaitGroup, m *sync.Mutex) {
defer wg.Done()
de.LogPrintln("starting")
// funcCount is the number of bench functions available and tested.
funcCount := len(bench.Functions)
// stats for the current algo.
algoStats := make([][]stats.Stats, funcCount)
// ch serves as a way to get the actual computed output.
ch := make(chan []stats.Stats, funcCount)
defer close(ch)
// jDE params.
np := 50
f := 0.5
cr := 0.9
for i := range algoStats {
jDE := de.NewjDE()
// params:
// Generations, mutation strategy, parameter self-adaptation scheme,
// initial population size, differential weight, mutation constant,
// dimensions, bench name and a synchronisation channel.
//
// -1 to disable generation limits,
// 0..17 to choose a mutation strategy,
// 0..1 to select a parameter self-adaptation scheme,
// np >= 4 as initial population size.
jDE.Init(-1, 0, 0, np, f, cr, bench.DimensionsGA, bench.FuncNames[i], ch)
go jDE.Run()
}
// get results.
for i := range algoStats {
s := <-ch
algoStats[i] = s
}
pCh := make(chan report.PicList, funcCount*len(bench.DimensionsGA))
pMeanCh := make(chan report.PicList, funcCount*len(bench.DimensionsGA))
for _, algoStat := range algoStats {
go plotAllDims(algoStat, "plot", ".pdf", pCh, pMeanCh)
}
pLs := []report.PicList{}
pLsMean := []report.PicList{}
for range algoStats {
pL := <-pCh
pLMean := <-pMeanCh
pLs = append(pLs, pL)
pLsMean = append(pLsMean, pLMean)
}
algoName := "Self-adapting Differential Evolution"
// protect access to shared data.
m.Lock()
report.SavePicsToFile(pLs, pLsMean, algoName)
stats.SaveTable(algoName, algoStats)
m.Unlock()
}

@ -208,8 +208,8 @@ func plotMeanVals(meanVals []float64, title string, fes int) *plot.Plot {
return p
}
// violating gocognit 30, TODO(me): still split this up.
// nolint: gocognit
// violating gocognit 30, TODO(me): still split this up. fPrefix is always "plot" according to unparam.
// nolint: gocognit,unparam
func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.PicList, chMean chan report.PicList) {
start := time.Now()

@ -25,6 +25,9 @@ var (
// Dimensions to compute for (spatial complexity..?).
Dimensions = []int{5, 10, 20}
// DimensionsGA are used with Genetic Algorithms (such as DE, see algo/de).
DimensionsGA = []int{10, 30}
// SchwefelParams is a struct holding the min, max allowed value of inputs
// passed to the Schwefel function.
SchwefelParams = funcParams{min: -500.0, max: 500.0}