Documentation
¶
Index ¶
- Constants
- Variables
- func BasicBarrier(x []float64, params []Param) float64
- type BarrierFunc
- type BoundsMethod
- type Cov
- type Exploration
- type ExponentialParam
- type GP
- func (gp *GP) Add(x []float64, y float64)
- func (gp GP) Dims() int
- func (gp *GP) Estimate(x []float64) (float64, float64, error)
- func (gp *GP) Gradient(x []float64) ([]float64, error)
- func (gp *GP) Maximum() (x []float64, y float64)
- func (gp *GP) Minimum() (x []float64, y float64)
- func (gp GP) Name(i int) string
- func (gp GP) OutputName() string
- func (gp GP) RawData() ([][]float64, []float64)
- func (gp *GP) SetNames(inputs []string, output string)
- type LogBarrier
- type MaternCov
- type NormalParam
- type Optimizer
- func (o *Optimizer) ExplorationErr() error
- func (o *Optimizer) GP() *GP
- func (o *Optimizer) Log(x map[Param]float64, y float64)
- func (o *Optimizer) Next() (x map[Param]float64, parallel bool, err error)
- func (o *Optimizer) Predict(X []map[Param]float64, Y []float64) (x map[Param]float64, err error)
- func (o *Optimizer) Rounds() int
- func (o *Optimizer) Run(f func(map[Param]float64) float64) (x map[Param]float64, y float64, err error)
- func (o *Optimizer) RunSerial(f func(map[Param]float64) float64) (x map[Param]float64, y float64, err error)
- func (o *Optimizer) Running() bool
- func (o *Optimizer) Stop()
- type OptimizerOption
- func WithBarrierFunc(bf BarrierFunc) OptimizerOption
- func WithExploration(exploration Exploration) OptimizerOption
- func WithMinimize(minimize bool) OptimizerOption
- func WithOutputName(name string) OptimizerOption
- func WithRandomRounds(rounds int) OptimizerOption
- func WithRounds(rounds int) OptimizerOption
- type Param
- type RejectionParam
- type UCB
- type UniformParam
Constants ¶
const ( // DefaultRounds is the default number of rounds to run. DefaultRounds = 20 // DefaultRandomRounds is the default number of random rounds to run. DefaultRandomRounds = 5 // DefaultMinimize is the default value of minimize. DefaultMinimize = true // NumRandPoints is the maximum allowed number of evaluations. NumRandPoints = 100000 // NumGradPoints is the number of random points of gradient descent NumGradPoints = 256 )
Variables ¶
var ( // DefaultExploration uses UCB with 95 confidence interval. DefaultExploration = UCB{Kappa: 1.96} // DefaultBarrierFunc sets the default barrier function to use. DefaultBarrierFunc = LogBarrier{} )
var SampleTries = 1000
SampleTries is the number of tries a sample function should try before truncating the samples to the boundaries.
Functions ¶
func BasicBarrier ¶
BasicBarrier returns -Inf if an x value is outside the param range.
Types ¶
type BarrierFunc ¶
type BarrierFunc interface { Val(x []float64, params []Param) float64 Grad(x []float64, params []Param) []float64 }
BarrierFunc returns a value that is added to the value to bound the optimization.
type BoundsMethod ¶
BoundsMethod is a hack that contains the target space.
type Exploration ¶
Exploration is the strategy to use for exploring the Gaussian process.
type ExponentialParam ¶
ExponentialParam is an exponentially distributed parameter between 0 and in the range (0, +math.MaxFloat64] whose rate parameter (lambda) is Rate and whose mean is 1/lambda (1). The Max and Min parameters use discard sampling to find a point between them. Set them to be math.Inf(1) and math.Inf(-1) to disable the bounds.
func (ExponentialParam) GetMax ¶
func (p ExponentialParam) GetMax() float64
GetMax implements Param.
func (ExponentialParam) GetMin ¶
func (p ExponentialParam) GetMin() float64
GetMin implements Param.
func (ExponentialParam) GetName ¶
func (p ExponentialParam) GetName() string
GetName implements Param.
func (ExponentialParam) Sample ¶
func (p ExponentialParam) Sample() float64
Sample implements Param.
type GP ¶
type GP struct {
// contains filtered or unexported fields
}
GP represents a gaussian process.
func NewGP ¶
NewGP creates a new Gaussian process with the specified covariance function (cov) and noise level (variance).
type LogBarrier ¶
type LogBarrier struct{}
LogBarrier implements a logarithmic barrier function.
type MaternCov ¶
type MaternCov struct{}
MaternCov calculates the covariance between a and b. nu = 2.5 https://en.wikipedia.org/wiki/Mat%C3%A9rn_covariance_function#Simplification_for_.CE.BD_half_integer
type NormalParam ¶
NormalParam is a normally distributed parameter with Mean and StdDev. The Max and Min parameters use discard sampling to find a point between them. Set them to be math.Inf(1) and math.Inf(-1) to disable the bounds.
type Optimizer ¶
type Optimizer struct {
// contains filtered or unexported fields
}
Optimizer is a blackbox gaussian process optimizer.
func NewOptimizer ¶
func NewOptimizer(params []Param, opts ...OptimizerOption) *Optimizer
NewOptimizer creates a new optimizer with the specified optimizable parameters and options.
func (*Optimizer) ExplorationErr ¶
ExplorationErr returns the error of exploration
func (*Optimizer) GP ¶
GP returns the underlying gaussian process. Primary for use with plotting behavior.
func (*Optimizer) Next ¶
Next returns the next best x values to explore. If more than rounds have elapsed, nil is returned. If parallel is true, that round can happen in parallel to other rounds.
func (*Optimizer) Run ¶
func (o *Optimizer) Run(f func(map[Param]float64) float64) (x map[Param]float64, y float64, err error)
Run will call f the fewest times as possible while trying to maximize the output value. It blocks until all rounds have elapsed, or Stop is called.
func (*Optimizer) RunSerial ¶
func (o *Optimizer) RunSerial(f func(map[Param]float64) float64) (x map[Param]float64, y float64, err error)
RunSerial will call f sequentially without parallelism. It blocks until all rounds have elapsed, or Stop is called.
type OptimizerOption ¶
type OptimizerOption func(*Optimizer)
OptimizerOption sets an option on the optimizer.
func WithBarrierFunc ¶
func WithBarrierFunc(bf BarrierFunc) OptimizerOption
WithBarrierFunc sets the barrier function to use.
func WithExploration ¶
func WithExploration(exploration Exploration) OptimizerOption
WithExploration sets the exploration function to use.
func WithMinimize ¶
func WithMinimize(minimize bool) OptimizerOption
WithMinimize sets whether or not to minimize. Passing false, maximizes instead.
func WithOutputName ¶
func WithOutputName(name string) OptimizerOption
WithOutputName sets the outputs name. Only really matters if you're planning on using gp/plot.
func WithRandomRounds ¶
func WithRandomRounds(rounds int) OptimizerOption
WithRandomRounds sets the number of random rounds to run.
func WithRounds ¶
func WithRounds(rounds int) OptimizerOption
WithRounds sets the total number of rounds to run.
type Param ¶
type Param interface { // GetName returns the name of the parameter. GetName() string // GetMax returns the maximum value. GetMax() float64 // GetMin returns the minimum value. GetMin() float64 // Sample returns a random point within the bounds. It doesn't have to be // uniformly distributed. Sample() float64 }
Param represents a parameter that can be optimized.
type RejectionParam ¶
RejectionParam samples from Param and then uses F to decide whether or not to reject the sample. This is typically used with a UniformParam. F should output a value between 0 and 1 indicating the proportion of samples this point should be accepted. If F always outputs 0, Sample will get stuck in an infinite loop.
type UniformParam ¶
UniformParam is a uniformly distributed parameter between Max and Min.