-
Notifications
You must be signed in to change notification settings - Fork 22
/
sampler_option.go
95 lines (81 loc) · 3.18 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package tpe
import (
"math/rand"
"github.com/c-bata/goptuna"
)
// SamplerOption is a type of the function to customizing TPE sampler.
type SamplerOption func(sampler *Sampler)
// SamplerOptionSeed sets seed number.
func SamplerOptionSeed(seed int64) SamplerOption {
randomSampler := goptuna.NewRandomSampler(
goptuna.RandomSamplerOptionSeed(seed))
return func(sampler *Sampler) {
sampler.rng = rand.New(rand.NewSource(seed))
sampler.randomSampler = randomSampler
}
}
// SamplerOptionConsiderPrior enhance the stability of Parzen estimator
// by imposing a Gaussian prior when True. The prior is only effective
// if the sampling distribution is either `UniformDistribution`,
// `DiscreteUniformDistribution`, `LogUniformDistribution`, or `IntUniformDistribution`.
func SamplerOptionConsiderPrior(considerPrior bool) SamplerOption {
return func(sampler *Sampler) {
sampler.params.ConsiderPrior = considerPrior
}
}
// SamplerOptionPriorWeight sets the weight of the prior.
func SamplerOptionPriorWeight(priorWeight float64) SamplerOption {
return func(sampler *Sampler) {
sampler.params.PriorWeight = priorWeight
}
}
// SamplerOptionPriorWeight enable a heuristic to limit the smallest variances
// of Gaussians used in the Parzen estimator.
func SamplerOptionConsiderMagicClip(considerMagicClip bool) SamplerOption {
return func(sampler *Sampler) {
sampler.params.ConsiderMagicClip = considerMagicClip
}
}
// SamplerOptionConsiderEndpoints take endpoints of domains into account
// when calculating variances of Gaussians in Parzen estimator.
// See the original paper for details on the heuristics to calculate the variances.
func SamplerOptionConsiderEndpoints(considerEndpoints bool) SamplerOption {
return func(sampler *Sampler) {
sampler.params.ConsiderEndpoints = considerEndpoints
}
}
// SamplerOptionWeights sets the function that takes the number of finished trials
// and returns a weight for them. See `Making a Science of Model Search: Hyperparameter
// Optimization in Hundreds of Dimensions for Vision Architectures
// <http://proceedings.mlr.press/v28/bergstra13.pdf>` for more details.
func SamplerOptionWeights(weights func(x int) []float64) SamplerOption {
return func(sampler *Sampler) {
sampler.params.Weights = weights
}
}
// SamplerOptionGammaFunc sets the function that takes the number of
// finished trials and returns the number of trials to form a density
// function for samples with low grains.
func SamplerOptionGammaFunc(gamma FuncGamma) SamplerOption {
return func(sampler *Sampler) {
sampler.gamma = gamma
}
}
// SamplerOptionNumberOfEICandidates sets the number of EI candidates (default 24).
func SamplerOptionNumberOfEICandidates(n int) SamplerOption {
return func(sampler *Sampler) {
sampler.numberOfEICandidates = n
}
}
// SamplerOptionNumberOfStartupTrials sets the number of start up trials (default 10).
func SamplerOptionNumberOfStartupTrials(n int) SamplerOption {
return func(sampler *Sampler) {
sampler.numberOfStartupTrials = n
}
}
// SamplerOptionParzenEstimatorParams sets the parameter of ParzenEstimator.
func SamplerOptionParzenEstimatorParams(params ParzenEstimatorParams) SamplerOption {
return func(sampler *Sampler) {
sampler.params = params
}
}