-
Notifications
You must be signed in to change notification settings - Fork 1
/
optimize.go
90 lines (74 loc) · 2.06 KB
/
optimize.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package cmd
import (
"fmt"
"github.com/PolymerGuy/golmes/minimize"
"github.com/PolymerGuy/golmes/output"
"github.com/PolymerGuy/golmes/yamlparser"
"github.com/urfave/cli"
"io/ioutil"
"log"
"os"
)
var Optimize = cli.Command{
Name: "run",
Usage: "Run optimization",
Description: `Bla bla bla`,
Action: optimize,
}
func optimize(c *cli.Context) {
args := c.Args()
if len(args) == 0 {
log.Panic("No input was received")
os.Exit(1)
} else {
yamlFileName := args.Get(0)
file, err := ioutil.ReadFile(yamlFileName)
if err != nil {
log.Fatal(err)
}
coarseSeach, optJob, err := optJobFromYAML(file)
if err != nil {
log.Fatal(err)
}
if coarseSeach != nil {
for _, task := range coarseSeach {
// Do a response surface naive search
coarseResults, err := minimize.CoarseSearchSurf(optJob, task)
if err != nil {
log.Println(err)
}
// Use the results from the coarse search as initial parameters
optJob.InitialParameters = coarseResults
log.Println("Snip here...")
}
}
// Do a fine search
res, err := minimize.FindFunctionMinima(optJob)
if err != nil {
log.Panic(err)
}
log.Println("Fine search gave:")
output.PrettyPrint(res)
}
}
func optJobFromYAML(yamlFile []byte) ([]yamlparser.CoarseSearchSettings, minimize.OptimizationJob, error) {
parser := yamlparser.Parse(yamlFile)
fmt.Println(parser.AbqSettings)
fmt.Println(parser.SolverSettings)
coarseSearchs := []yamlparser.CoarseSearchSettings{}
//TODO: Remove list of comparators. This should be impossible...
comparator := parser.NewComparator()[0]
costFunction := parser.NewCostFunction()
method := parser.NewOptimizerMethod()
costFunction.Comparator = comparator
settings := parser.NewOptimizerSettings()
coarseSearch := parser.NewCoarseSearch()
coarseSearchs = append(coarseSearchs, coarseSearch)
optJob := minimize.OptimizationJob{
InitialParameters: costFunction.InitialParameters,
Method: method,
CostFunc: costFunction,
Settings: settings,
}
return coarseSearchs, optJob, nil
}