Example #1
0
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()
	}
}
Example #2
0
func TestBenchSwarmRosen(t *testing.T) {
	ndim := 30
	npar := 30
	maxiter := 10000
	successfrac := 1.00
	avgiter := 500.0

	fn := bench.Rosenbrock{ndim}
	sfn := func() *optim.Solver {
		return &optim.Solver{
			Method:  swarmsolver(fn, nil, npar),
			Obj:     optim.Func(fn.Eval),
			MaxEval: maxiter * npar,
			MaxIter: maxiter,
		}
	}
	bench.Benchmark(t, fn, sfn, successfrac, avgiter)
}
Example #3
0
func TestOverviewSwarm(t *testing.T) {
	maxeval := 50000
	maxiter := 5000
	successfrac := 1.00
	avgiter := 250.0

	for _, fn := range bench.Basic {
		sfn := func() *optim.Solver {
			return &optim.Solver{
				Method:  swarmsolver(fn, nil, -1),
				Obj:     optim.Func(fn.Eval),
				MaxEval: maxeval,
				MaxIter: maxiter,
			}
		}
		bench.Benchmark(t, fn, sfn, successfrac, avgiter)
	}
}
Example #4
0
func TestBenchPSwarmRastrigrin(t *testing.T) {
	ndim := 30
	npar := 30
	maxiter := 10000
	successfrac := 1.00
	avgiter := 130.0

	fn := bench.Rastrigrin{ndim}
	sfn := func() *optim.Solver {
		m, mesh := pswarmsolver(fn, nil, npar)
		return &optim.Solver{
			Method:  m,
			Obj:     optim.Func(fn.Eval),
			Mesh:    mesh,
			MaxEval: maxiter * npar,
			MaxIter: maxiter,
		}
	}
	bench.Benchmark(t, fn, sfn, successfrac, avgiter)
}
Example #5
0
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")
	}
}
Example #6
0
func TestOverviewPattern(t *testing.T) {
	maxeval := 50000
	maxiter := 5000
	successfrac := 0.50
	avgiter := 2500.0

	// 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)
			m.Poller = &pattern.Poller{Spanner: pattern.CompassNp1{}}
			return &optim.Solver{
				Method:  m,
				Obj:     optim.Func(fn.Eval),
				Mesh:    mesh,
				MaxIter: maxiter,
				MaxEval: maxeval,
			}
		}
		bench.Benchmark(t, fn, sfn, successfrac, avgiter)
	}
}
Example #7
0
func TestBenchPSwarmRosen(t *testing.T) {
	ndim := 30
	npar := 30
	maxiter := 10000
	successfrac := 1.0
	avgiter := 300.0

	fn := bench.Rosenbrock{ndim}
	sfn := func() *optim.Solver {
		m, mesh := pswarmsolver(fn, nil, npar)
		low, _ := fn.Bounds()
		ndim := len(low)
		m.Poller = &pattern.Poller{Spanner: &pattern.RandomN{N: ndim}}
		return &optim.Solver{
			Method:  m,
			Obj:     optim.Func(fn.Eval),
			Mesh:    mesh,
			MaxEval: maxiter * npar,
			MaxIter: maxiter,
		}
	}
	bench.Benchmark(t, fn, sfn, successfrac, avgiter)
}