go(de): add Run(), unexport Evolve()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* use evolve() * add a way to calculate GAMaxFES (MaxFES for Genetic Algorithms) in the bench package
This commit is contained in:
parent
525b30c38e
commit
2216b93426
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"git.dotya.ml/wanderer/math-optim/bench"
|
||||
"git.dotya.ml/wanderer/math-optim/stats"
|
||||
)
|
||||
|
||||
@ -105,13 +106,38 @@ func (j *JDE) Init(generations, mutStrategy, adptScheme, np int, f, cr float64,
|
||||
pop.Init()
|
||||
}
|
||||
|
||||
// Evolve evolves a population by running the jDE (self-adapting Differential
|
||||
// Run self-adapting differential evolution algorithm.
|
||||
func (j *JDE) Run() {
|
||||
if j == nil {
|
||||
jDELogger.Fatalln("jDE is nil, NewjDE() needs to be called first. exiting...")
|
||||
}
|
||||
|
||||
if !j.initialised {
|
||||
jDELogger.Fatalln("jDE needs to be initialised before calling Run(), exiting...")
|
||||
}
|
||||
|
||||
// have a wait group.
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// we're be spawning goroutines per dimension and that is the number of
|
||||
// goroutines we need to wait for.
|
||||
wg.Add(len(j.Dimensions))
|
||||
|
||||
// run Evolve for for all dimensions.
|
||||
for _, dim := range j.Dimensions {
|
||||
maxFES := bench.GetGAMaxFES(dim)
|
||||
|
||||
j.evolve(maxFES, &wg)
|
||||
}
|
||||
|
||||
// wait for all.
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// evolve evolves a population by running the jDE (self-adapting Differential
|
||||
// Evolution) algorithm on the passed population until termination conditions
|
||||
// are met.
|
||||
func (j *JDE) Evolve(maxFES int, wg *sync.WaitGroup) {}
|
||||
|
||||
// Run self-adapting differential evolution algorithm.
|
||||
func RunjDE(jDE *JDE) {}
|
||||
func (j *JDE) evolve(maxFES int, wg *sync.WaitGroup) {}
|
||||
|
||||
// NewjDE returns a pointer to a new, uninitialised jDE instance.
|
||||
func NewjDE() *JDE {
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
package bench
|
||||
|
||||
import "log"
|
||||
|
||||
type funcParams struct {
|
||||
min float64
|
||||
max float64
|
||||
@ -46,3 +48,13 @@ func (f *funcParams) Min() float64 {
|
||||
func (f *funcParams) Max() float64 {
|
||||
return f.max
|
||||
}
|
||||
|
||||
// GetGAMaxFES calculates the value of MaxFES for Genetic Algorithms. This is
|
||||
// an arbitrary specification where MaxFES is 5000xD.
|
||||
func GetGAMaxFES(dim int) int {
|
||||
if dim <= 0 {
|
||||
log.Fatalln("dim has to be greater than 0, got:", dim)
|
||||
}
|
||||
|
||||
return dim * 5000
|
||||
}
|
||||
|
@ -62,3 +62,13 @@ func TestDeJong2Params(t *testing.T) {
|
||||
t.Errorf("wrong DeJong2Params, want: %+v, got: %+v", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetGAMaxFES(t *testing.T) {
|
||||
dim := 3
|
||||
want := 15000
|
||||
got := GetGAMaxFES(dim)
|
||||
|
||||
if want != got {
|
||||
t.Errorf("wrong GAMaxFES result, want: %d, got: %d", want, got)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user