optimize: Remove Local function (#538)

* optimize: Remove Local function

This change removes the Local function. In order to do so, this changes the previous LocalGlobal wrapper to LocalController to allow Local methods to be used as a Global optimizer. This adds methods to all of the Local methods in order to implement GlobalMethod, and changes the tests accordingly. The next commit will fix all of the names
This commit is contained in:
Brendan Tracey
2018-07-18 12:18:18 -06:00
committed by GitHub
parent 023b8e605a
commit 2704973b50
10 changed files with 229 additions and 199 deletions

View File

@@ -1154,7 +1154,7 @@ func TestNewton(t *testing.T) {
testLocal(t, newtonTests, &Newton{})
}
func testLocal(t *testing.T, tests []unconstrainedTest, method Method) {
func testLocal(t *testing.T, tests []unconstrainedTest, method GlobalMethod) {
for cas, test := range tests {
if test.long && testing.Short() {
continue
@@ -1180,7 +1180,9 @@ func testLocal(t *testing.T, tests []unconstrainedTest, method Method) {
}
settings.GradientThreshold = test.gradTol
result, err := Local(test.p, test.x, settings, method)
dim := len(test.x)
settings.InitX = test.x
result, err := Global(test.p, dim, settings, method)
if err != nil {
t.Errorf("Case %d: error finding minimum (%v) for:\n%v", cas, err, test)
continue
@@ -1244,7 +1246,7 @@ func testLocal(t *testing.T, tests []unconstrainedTest, method Method) {
// Rerun the test again to make sure that it gets the same answer with
// the same starting condition. Moreover, we are using the initial data.
result2, err2 := Local(test.p, test.x, settings, method)
result2, err2 := Global(test.p, dim, settings, method)
if err2 != nil {
t.Errorf("error finding minimum second time (%v) for:\n%v", err2, test)
continue
@@ -1296,7 +1298,8 @@ func TestIssue76(t *testing.T) {
Linesearcher: &Backtracking{},
}
// We are not interested in the error, only in the returned status.
r, _ := Local(p, x, s, m)
s.InitX = x
r, _ := Global(p, len(x), s, m)
// With the above stringent tolerance, the optimizer will never
// successfully reach the minimum. Check if it terminated in a finite
// number of steps.