github.com/gopherd/gonum@v0.0.4/optimize/guessandcheck_test.go (about) 1 // Copyright ©2016 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package optimize 6 7 import ( 8 "testing" 9 10 "github.com/gopherd/gonum/mat" 11 "github.com/gopherd/gonum/optimize/functions" 12 "github.com/gopherd/gonum/stat/distmv" 13 ) 14 15 func TestGuessAndCheck(t *testing.T) { 16 t.Parallel() 17 dim := 30 18 problem := Problem{ 19 Func: functions.ExtendedRosenbrock{}.Func, 20 } 21 mu := make([]float64, dim) 22 sigma := mat.NewSymDense(dim, nil) 23 for i := 0; i < dim; i++ { 24 sigma.SetSym(i, i, 1) 25 } 26 d, ok := distmv.NewNormal(mu, sigma, nil) 27 if !ok { 28 panic("bad test") 29 } 30 initX := make([]float64, dim) 31 _, err := Minimize(problem, initX, nil, &GuessAndCheck{Rander: d}) 32 if err != nil { 33 t.Errorf("unexpected error running Minimize with nil settings: %v", err) 34 } 35 36 settings := &Settings{} 37 settings.Concurrent = 5 38 settings.MajorIterations = 15 39 _, err = Minimize(problem, initX, settings, &GuessAndCheck{Rander: d}) 40 if err != nil { 41 t.Errorf("unexpected error running Minimize with settings %+v: %v", settings, err) 42 } 43 }