Skip to content
This repository was archived by the owner on Nov 23, 2018. It is now read-only.

Commit 53e207c

Browse files
committed
optimize: add example for Local+BFGS
This CL adds a simple example, extracted from: http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize
1 parent 329a25f commit 53e207c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

local_example_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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_test
6+
7+
import (
8+
"fmt"
9+
"log"
10+
11+
"github.com/gonum/optimize"
12+
"github.com/gonum/optimize/functions"
13+
)
14+
15+
func ExampleLocal_BFGS() {
16+
p := optimize.Problem{
17+
Func: functions.ExtendedRosenbrock{}.Func,
18+
Grad: functions.ExtendedRosenbrock{}.Grad,
19+
}
20+
21+
x := []float64{1.3, 0.7, 0.8, 1.9, 1.2}
22+
settings := optimize.DefaultSettings()
23+
settings.Recorder = nil
24+
settings.GradientThreshold = 1e-12
25+
settings.FunctionConverge = nil
26+
27+
result, err := optimize.Local(p, x, settings, &optimize.BFGS{})
28+
if err != nil {
29+
log.Fatal(err)
30+
}
31+
if err = result.Status.Err(); err != nil {
32+
log.Fatal(err)
33+
}
34+
fmt.Printf("result.Status: %v\n", result.Status)
35+
fmt.Printf("result.X: %v\n", result.X)
36+
fmt.Printf("result.F: %v\n", result.F)
37+
fmt.Printf("result.Stats.FuncEvaluations: %d\n", result.Stats.FuncEvaluations)
38+
// Output:
39+
// result.Status: GradientThreshold
40+
// result.X: [1 1 1 1 1]
41+
// result.F: 0
42+
// result.Stats.FuncEvaluations: 35
43+
}

0 commit comments

Comments
 (0)