Files
gonum/optimize/guessandcheck_test.go
Brendan Tracey 996b88e8f8 optimize: completely overhaul Global (#352)
* optimize: completely overhaul Global

The previous implementation of Global was a minefield for incorrectly implementing global optimization methods. It was very difficult to correctly implement methods (both of the provided methods were incorrect), and the resulting code is very ugly. This commit switches to use channels to communicate, allowing a more clear ordering of concurrent code. This also enables better shutdown of methods.

In addition to the main fix of Global, this refactors the two Global methods to use the updated interface, and makes some small improvements that were previously not possible. In addition, there are some small cleanups of Local to better match between the two calls.

If anyone has been curious about what is meant by 'Don't communicate by sharing memory, share memory by communicating' this is it, and why.

* respond to PR comments

* make constants

* simplify termination logic

* optimize: simplify stats collection

* overhaul documentation and respond to PR comments

* implement PR requests

* clean up cmaes
2018-02-05 08:44:02 -07:00

36 lines
833 B
Go

// Copyright ©2016 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package optimize
import (
"testing"
"gonum.org/v1/gonum/mat"
"gonum.org/v1/gonum/optimize/functions"
"gonum.org/v1/gonum/stat/distmv"
)
func TestGuessAndCheck(t *testing.T) {
dim := 3000
problem := Problem{
Func: functions.ExtendedRosenbrock{}.Func,
}
mu := make([]float64, dim)
sigma := mat.NewSymDense(dim, nil)
for i := 0; i < dim; i++ {
sigma.SetSym(i, i, 1)
}
d, ok := distmv.NewNormal(mu, sigma, nil)
if !ok {
panic("bad test")
}
Global(problem, dim, nil, &GuessAndCheck{Rander: d})
settings := DefaultSettingsGlobal()
settings.Concurrent = 5
settings.MajorIterations = 15
Global(problem, dim, settings, &GuessAndCheck{Rander: d})
}