optimization

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package optimization helps to find better configuration of your service or library.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidParameterCombination = errors.New("invalid parameter combination")

ErrInvalidParameterCombination notifies optimizer about invalid combination of parameters. CostFunction must return MaxCost and ErrInvalidParameterCombination if it happened.

Functions

This section is empty.

Types

type Bound

type Bound struct {
	From int `json:"from"`
	To   int `json:"to"`
}

Bound describes reasonable bounds for parameter variation.

type ConfigModifier

type ConfigModifier func(int)

ConfigModifier injects parameter value received from the optimizer into configuration instance.

type Cost

type Cost = float64

Cost represents the value returned by cost function.

type CostFunction

type CostFunction func(ctx context.Context) (Cost, error)

CostFunction (or objective function) is implemented by clients. Optimizer will try to find the best possible combination of your parameters on the basis of this function. CostFunction call is expected to be expensive, so client should check context expiration.

type InitStrategy added in v0.4.0

type InitStrategy int8

InitStrategy determines the way RBFOpt selects points.

const (
	LHDMaximin InitStrategy = iota
	LHDCorr
	AllCorners
	LowerCorners
	RandCorners
)

func (InitStrategy) MarshalJSON added in v0.4.0

func (s InitStrategy) MarshalJSON() ([]byte, error)

MarshalJSON renders InitStrategy to JSON.

type ParameterDescription

type ParameterDescription struct {
	Bound          *Bound         `json:"bound"`
	ConfigModifier ConfigModifier `json:"-"`
	Name           string         `json:"name"`
}

ParameterDescription is something you want to optimization in your service configuration.

type ParameterValue

type ParameterValue struct {
	Name  string
	Value int
}

ParameterValue describes some value of a CostFunction argument.

type Report

type Report struct {
	Cost            Cost              `json:"cost"`    // Discovered optimal value of a CostFunction
	Optimum         []*ParameterValue `json:"optimum"` // Parameter values matching the optimum point
	Iterations      int               `json:"iterations"`
	Evaluations     int               `json:"evaluations"`
	FastEvaluations int               `json:"fast_evaluations"`
}

Report contains information about the finished optimization process

func Optimize

func Optimize(ctx context.Context, settings *Settings) (*Report, error)

Optimize is an entry point for the optimization routines. One may want to pass logger within context to have detailed logs.

type Settings

type Settings struct {
	// RootDir - place to store reports and other things
	// (optimizer will create it if it doesn't exist).
	RootDir string
	// CostFunction itself
	CostFunction CostFunction
	// Arguments of a CostFunctions
	Parameters []*ParameterDescription
	// RBFOpt: limits number of evaluations
	MaxEvaluations uint
	// RBFOpt: limits number of iterations
	MaxIterations uint
	// RBFOpt: reason: https://github.com/coin-or/rbfopt/issues/28
	InvalidParameterCombinationCost Cost
	// Set to true if you don't want to see large values corresponding to the ErrInvalidParametersCombination on your plots
	SkipInvalidParameterCombinationOnPlots bool
	// Strategy to select initial points.
	InitStrategy InitStrategy
}

Settings contains the description of what and how to optimize.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL