func TestOverviewSwarm(t *testing.T) { maxeval := 50000 avgeval := 7500.00 successfrac := 1.00 for _, fn := range bench.Basic { sfn := func() *optim.Solver { return &optim.Solver{ Method: swarmsolver(fn, nil, -1), Obj: optim.Func(fn.Eval), MaxEval: maxeval, } } bench.Benchmark(t, fn, sfn, successfrac, avgeval) } }
func BenchmarkSwarmRosen(b *testing.B) { ndim := 30 npar := 30 maxiter := 10000 fn := bench.Rosenbrock{ndim} for i := 0; i < b.N; i++ { m, mesh := swarmsolver(fn, nil) solv := &optim.Solver{ Method: m, Obj: optim.Func(fn.Eval), Mesh: mesh, MaxEval: maxiter * npar, MaxIter: maxiter, } solv.Run() } }
func TestBenchSwarmRastrigin(t *testing.T) { ndim := 20 npar := 30 maxeval := 30000 avgeval := 18000.0 successfrac := 0.50 fn := bench.Rastrigin{ndim} sfn := func() *optim.Solver { return &optim.Solver{ Method: swarmsolver(fn, nil, npar), Obj: optim.Func(fn.Eval), MaxEval: maxeval, } } bench.Benchmark(t, fn, sfn, successfrac, avgeval) }
func TestBenchSwarmGriewank(t *testing.T) { ndim := 30 npar := 30 maxeval := 120000 avgeval := 80000.0 successfrac := 0.80 fn := bench.Griewank{ndim} sfn := func() *optim.Solver { return &optim.Solver{ Method: swarmsolver(fn, nil, npar), Obj: optim.Func(fn.Eval), MaxEval: maxeval, } } bench.Benchmark(t, fn, sfn, successfrac, avgeval) }
func TestBenchPSwarmRosen(t *testing.T) { ndim := 30 npar := 30 maxeval := 300000 avgeval := 10000.0 successfrac := 1.0 fn := bench.Rosenbrock{ndim} sfn := func() *optim.Solver { m, mesh := pswarmsolver(fn, nil, npar) return &optim.Solver{ Method: m, Obj: optim.Func(fn.Eval), Mesh: mesh, MaxEval: maxeval, } } bench.Benchmark(t, fn, sfn, successfrac, avgeval) }
func TestOverviewPattern(t *testing.T) { maxeval := 20000 avgeval := 15000.0 successfrac := 0.23 // ONLY test plain pattern search on convex functions for _, fn := range []bench.Func{bench.Rosenbrock{NDim: 2}} { sfn := func() *optim.Solver { m, mesh := patternsolver(fn, nil) return &optim.Solver{ Method: m, Obj: optim.Func(fn.Eval), Mesh: mesh, MaxEval: maxeval, } } bench.Benchmark(t, fn, sfn, successfrac, avgeval) } }
func TestDb(t *testing.T) { db, err := sql.Open("sqlite3", ":memory:") if err != nil { t.Fatal(err) } defer db.Close() fn := bench.Basic[0] optimum := fn.Optima()[0].Val it, m := patternsolver(fn, db) solv := &optim.Solver{ Method: it, Obj: optim.Func(fn.Eval), Mesh: m, MaxIter: 100, MinStep: -1, } err = solv.Run() if err != nil { log.Fatal(err) } t.Logf("[INFO] %v evals: want %v, got %v", solv.Neval(), optimum, solv.Best().Val) var count int err = db.QueryRow("SELECT COUNT(*) FROM " + TblPolls).Scan(&count) if err != nil { t.Errorf("[ERROR] polls table query failed: %v", err) } else if count == 0 { t.Errorf("[ERROR] polls table has no rows") } count = 0 err = db.QueryRow("SELECT COUNT(*) FROM " + TblInfo).Scan(&count) if err != nil { t.Errorf("[ERROR] info table query failed: %v", err) } else if count == 0 { t.Errorf("[ERROR] info table has no rows") } }