-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
35 lines (29 loc) · 804 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"log"
"math"
"github.com/c-bata/goptuna"
"github.com/c-bata/goptuna/sobol"
)
func objective(trial goptuna.Trial) (float64, error) {
x1, _ := trial.SuggestFloat("x1", -10, 10)
x2, _ := trial.SuggestFloat("x2", -10, 10)
return math.Pow(x1-2, 2) + math.Pow(x2+5, 2), nil
}
func main() {
relativeSampler := sobol.NewSampler()
study, err := goptuna.CreateStudy(
"goptuna-example",
goptuna.StudyOptionRelativeSampler(relativeSampler),
)
if err != nil {
log.Fatal("failed to create study:", err)
}
if err = study.Optimize(objective, 50); err != nil {
log.Fatal("failed to optimize:", err)
}
v, _ := study.GetBestValue()
params, _ := study.GetBestParams()
log.Printf("Best evaluation=%f (x1=%f, x2=%f)",
v, params["x1"].(float64), params["x2"].(float64))
}