-
Notifications
You must be signed in to change notification settings - Fork 22
/
sampler_option.go
68 lines (58 loc) · 2.07 KB
/
sampler_option.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
package cmaes
import (
"math/rand"
)
const (
restartStrategyIPOP = "ipop"
restartStrategyBIPOP = "bipop"
)
// SamplerOption is a type of the function to customizing CMA-ES sampler.
type SamplerOption func(sampler *Sampler)
// SamplerOptionSeed sets seed number.
func SamplerOptionSeed(seed int64) SamplerOption {
return func(sampler *Sampler) {
sampler.rng = rand.New(rand.NewSource(seed))
}
}
// SamplerOptionInitialMean sets the initial mean vectors.
func SamplerOptionInitialMean(mean map[string]float64) SamplerOption {
return func(sampler *Sampler) {
sampler.x0 = mean
}
}
// SamplerOptionInitialSigma sets the initial sigma.
func SamplerOptionInitialSigma(sigma float64) SamplerOption {
return func(sampler *Sampler) {
sampler.sigma0 = sigma
}
}
// SamplerOptionOptimizerOptions sets the options for Optimizer.
func SamplerOptionOptimizerOptions(opts ...OptimizerOption) SamplerOption {
return func(sampler *Sampler) {
sampler.optimizerOptions = opts
}
}
// SamplerOptionNStartupTrials sets the number of startup trials.
func SamplerOptionNStartupTrials(nStartupTrials int) SamplerOption {
return func(sampler *Sampler) {
sampler.nStartUpTrials = nStartupTrials
}
}
// SamplerOptionIPop enables restart CMA-ES with increasing population size.
// The argument is multiplier of population size before each restart and basically you should choose 2.
// From the experiments in the IPOP-CMA-ES, it reveal similar performance for factors between 2 and 3.
func SamplerOptionIPop(incPopSize int) SamplerOption {
return func(sampler *Sampler) {
sampler.restartStrategy = restartStrategyIPOP
sampler.incPopSize = incPopSize
}
}
// SamplerOptionBIPop enables restart CMA-ES with two interlaced restart strategies,
// one with an increasing population size and one with varying small population size.
// The argument is multiplier of population size before each restart and basically you should choose 2.
func SamplerOptionBIPop(incPopSize int) SamplerOption {
return func(sampler *Sampler) {
sampler.restartStrategy = restartStrategyBIPOP
sampler.incPopSize = incPopSize
}
}