// Copyright 2022 wanderer // SPDX-License-Identifier: GPL-3.0-or-later package algo import ( "sync" "git.dotya.ml/wanderer/math-optim/bench" "git.dotya.ml/wanderer/math-optim/report" "git.dotya.ml/wanderer/math-optim/stats" ) // Values type is just a fancy named []float64 that will allow us to define // methods over it. type Values []float64 // DoRandomSearch executes a search using the 'Random search' method. func DoRandomSearch(wg *sync.WaitGroup) { defer wg.Done() printRandomSearch("starting...") // funcCount is the number of bench functions available. funcCount := len(bench.Functions) // stats for the current algo (RandomSearch). algoStats := make([][]stats.Stats, funcCount) // ch serves as a way to get the actual computed output. ch := make(chan []stats.Stats, funcCount) for i := range algoStats { // ng y'all. go RandomSearchNG(10000, 30, []int{5, 10, 20}, bench.FuncNames[i], ch) } // get results. for i := range algoStats { s := <-ch algoStats[i] = s } pCh := make(chan report.PicList, funcCount*len(bench.Dimensions)) for i := range algoStats { go plotAllDims(algoStats[i], "plot", ".svg", pCh) } for range algoStats { pL := <-pCh report.SavePicsToFile(pL, "Random Search") } stats.SaveTable("Random Search", algoStats) } // DoStochasticHillClimbing performs a search using the 'Stochastic Hill // Climbing' method. func DoStochasticHillClimbing(wg *sync.WaitGroup) { defer wg.Done() printSHC("starting...") // funcCount is the number of bench functions available. funcCount := len(bench.Functions) // stats for the current algo (StochasticHillClimber). algoStats := make([][]stats.Stats, funcCount) // ch serves as a way to get the actual computed output. ch := make(chan []stats.Stats, funcCount) for i := range algoStats { go HillClimb(10000, 30, []int{5, 10, 20}, bench.FuncNames[i], ch) } // get results. for i := range algoStats { s := <-ch algoStats[i] = s } pCh := make(chan report.PicList, funcCount*len(bench.Dimensions)) for _, algoStat := range algoStats { go plotAllDims(algoStat, "plot", ".svg", pCh) } for range algoStats { pL := <-pCh report.SavePicsToFile(pL, "Stochastic Hill Climbing") } stats.SaveTable("Stochastic Hill CLimbing", algoStats) } func newValues() *Values { var v Values return &v }