Documentation ¶
Index ¶
- type ExitStatus
- type ExitStatusCode
- type FunctionWithGradient
- type GeneralObjectiveFunction
- type Lbfgsb
- func (lbfgsb *Lbfgsb) ClearBounds() *Lbfgsb
- func (lbfgsb *Lbfgsb) Init(dimensionality int) *Lbfgsb
- func (lbfgsb *Lbfgsb) Minimize(objective FunctionWithGradient, initialPoint []float64) (minimum PointValueGradient, exitStatus ExitStatus)
- func (lbfgsb *Lbfgsb) OptimizationStatistics() OptimizationStatistics
- func (lbfgsb *Lbfgsb) SetApproximationSize(size int) *Lbfgsb
- func (lbfgsb *Lbfgsb) SetBounds(bounds [][2]float64) *Lbfgsb
- func (lbfgsb *Lbfgsb) SetBoundsAll(lower, upper float64) *Lbfgsb
- func (lbfgsb *Lbfgsb) SetBoundsSparse(sparseBounds map[int][]float64) *Lbfgsb
- func (lbfgsb *Lbfgsb) SetFTolerance(fTolerance float64) *Lbfgsb
- func (lbfgsb *Lbfgsb) SetFortranPrintControl(verbosity int) *Lbfgsb
- func (lbfgsb *Lbfgsb) SetGTolerance(gTolerance float64) *Lbfgsb
- func (lbfgsb *Lbfgsb) SetLogger(logger OptimizationIterationLogger) *Lbfgsb
- type ObjectiveFunctionMinimizer
- type OptimizationIterationInformation
- type OptimizationIterationLogger
- type OptimizationStatistics
- type OptimizationStatisticser
- type PointValueGradient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExitStatus ¶
type ExitStatus struct { Code ExitStatusCode Message string }
ExitStatus is the exit status of an optimization algorithm. Includes a status code and a message explaining the situation.
func (ExitStatus) AsError ¶
func (es ExitStatus) AsError() error
AsError returns an error representing this exit status. If the exit status code is 'SUCCESS' then AsError returns nil. Otherwise returns an error object (which happens to be this object).
func (ExitStatus) Error ¶
func (es ExitStatus) Error() string
Error allows this ExitStatus to be treated like an error object.
func (ExitStatus) String ¶
func (es ExitStatus) String() string
String returns the exit status code and message as text.
type ExitStatusCode ¶
type ExitStatusCode uint8
ExitStatusCode describes the exit status of an optimization algorithm. Multiple statuses are necessary because success in optimization is not binary and so a simple error is not adequate. There are four exit statuses to distinguish:
1. Success. Normal termination having converged.
2. Approximate success. Normal operation resulting in a more approximate answer. For example, unable to meet termination tolerances.
3. Warning. The result could be OK, but there were some issues that may have reduced the quality of the result and require examination. For example, slight numerical problems, exceeding iteration or time bounds.
4. Failure of optimization. For example, a necessary condition of the algorithm was not met, severe numerical problems. (This status includes failures to evaluate the objective function or objective gradient.)
There are also the typical runtime errors due to usage, bugs, etc.:
5. Usage error. For example, invalid constraints, bad parameters. Responsibility is on the caller.
6. Internal error. Other runtime or programming/logic error which may be a bug. Responsibility is on this package.
const ( SUCCESS ExitStatusCode = iota APPROXIMATE WARNING FAILURE USAGE_ERROR INTERNAL_ERROR )
ExitStatusCode values.
func (ExitStatusCode) String ¶
func (esc ExitStatusCode) String() string
String returns a word for each ExitStatusCode.
type FunctionWithGradient ¶
type FunctionWithGradient interface { // Evaluate returns the value of the function at the given point. Evaluate(point []float64) float64 // EvaluateGradient returns the gradient of the function at the // given point. EvaluateGradient(point []float64) []float64 }
FunctionWithGradient is the interface for a function (f: R**n -> R) and its gradient (f': R**n -> R**n) suitable for use as an objective function for optimization.
type GeneralObjectiveFunction ¶
type GeneralObjectiveFunction struct { Function func([]float64) float64 Gradient func([]float64) []float64 }
GeneralObjectiveFunction is a utility object that combines individual Go functions into a FunctionWithGradient.
func (GeneralObjectiveFunction) Evaluate ¶
func (gof GeneralObjectiveFunction) Evaluate(point []float64) float64
func (GeneralObjectiveFunction) EvaluateGradient ¶
func (gof GeneralObjectiveFunction) EvaluateGradient(point []float64) []float64
type Lbfgsb ¶
type Lbfgsb struct {
// contains filtered or unexported fields
}
Lbfgsb provides the functionality of the Fortran L-BFGS-B optimizer as a Go object. A Lbfgsb solver object contains the setup for an optimization problem of a particular dimensionality. It stores bounds, parameters, and results so it is relatively lightweight (especially if no bounds are specified). It can be re-used for other problems with the same dimensionality, but using a different solver object for each problem is probably better organization. A zero-value Lbfgsb object is valid and needs no explicit construction. A solver object will perform unconstrained optimization unless bounds are set.
func NewLbfgsb ¶
NewLbfgsb creates, initializes, and returns a new Lbfgsb solver object. Equivalent to 'new(Lbfgsb).Init(dimensionality)'. A zero-value Lbfgsb object is valid and needs no explicit construction. However, this constructor is convenient and explicit.
func (*Lbfgsb) ClearBounds ¶
ClearBounds clears all bounds resulting in an unconstrained optimization problem.
func (*Lbfgsb) Init ¶
Init initializes this Lbfgsb solver for problems of the given dimensionality. Also sets default parameters that are not zero values. Returns this for method chaining. Ignores calls subsequent to the first (because a solver is intended for only a particular dimensionality).
func (*Lbfgsb) Minimize ¶
func (lbfgsb *Lbfgsb) Minimize( objective FunctionWithGradient, initialPoint []float64) ( minimum PointValueGradient, exitStatus ExitStatus)
Minimize optimizes the given objective using the L-BFGS-B algorithm. Implements OptimizationFunctionMinimizer.Minimize.
func (*Lbfgsb) OptimizationStatistics ¶
func (lbfgsb *Lbfgsb) OptimizationStatistics() OptimizationStatistics
Statistics returns some statistics about the most recent minimization: the total number of iterations and the total numbers of function and gradient evaluations.
func (*Lbfgsb) SetApproximationSize ¶
SetApproximationSize sets the amount of history (points and gradients) stored and used to approximate the inverse Hessian matrix. More history allows better approximation at the cost of more memory. The recommended range is [3,20]. Defaults to 5.
func (*Lbfgsb) SetBounds ¶
SetBounds sets the upper and lower bounds on the individual dimensions to the given intervals resulting in a constrained optimization problem. Individual bounds may be (+/-)Inf.
func (*Lbfgsb) SetBoundsAll ¶
SetBoundsAll sets the bounds of all the dimensions to [lower,upper]. Init must be called first to set the dimensionality.
func (*Lbfgsb) SetBoundsSparse ¶
SetBoundsSparse sets the bounds to only those in the given map; others are unbounded. Each entry in the map is a (zero-based) dimension index mapped to a slice representing an interval. Individual bounds may be (+/-)Inf. Init must be called first to set the dimensionality.
The slice is interpreted as an interval as follows:
nil | []: [-Inf, +Inf] [x]: [-|x|, |x|] [l, u, ...]: [l, u]
func (*Lbfgsb) SetFTolerance ¶
SetFTolerance sets the tolerance of the precision of the objective function required for convergence. Defaults to 1e-6.
func (*Lbfgsb) SetFortranPrintControl ¶
SetFortranPrintControl sets the level of output verbosity from the Fortran L-BFGS-B code. Defaults to 0, no output. Ranges from 0 to 102: 1 displays a summary, 100 displays details of each iteration, 102 adds vectors (X and G) to the output.
func (*Lbfgsb) SetGTolerance ¶
SetGTolerance sets the tolerance of the precision of the objective gradient required for convergence. Defaults to 1e-6.
func (*Lbfgsb) SetLogger ¶
func (lbfgsb *Lbfgsb) SetLogger( logger OptimizationIterationLogger) *Lbfgsb
SetLogger sets a logging function for the optimization that will be called after each iteration. May be nil, which disables logging. Defaults to nil.
type ObjectiveFunctionMinimizer ¶
type ObjectiveFunctionMinimizer interface { // Minimize finds a numerically-approximate minimum of the given // objective function starting from the given point. Returns the // minimum (or the best point found) and the status of the algorithm // at exit. Minimize(objective FunctionWithGradient, initialPoint []float64) ( minimum PointValueGradient, exitStatus ExitStatus) }
ObjectiveFunctionMinimizer is the interface for all n-dimensional numerical minimization optimization algorithms that use gradients. Finds a local minimum. The idea is that an optimization algorithm object will provide this method as well as methods for setting parameters, getting performance results, logging, etc., methods that are specific to the implementation. This interface should specify the minimum necessary to be a useful optimization algorithm.
type OptimizationIterationInformation ¶
type OptimizationIterationInformation struct { Iteration int FEvals int GEvals int FEvalsTotal int GEvalsTotal int StepLength float64 X []float64 F float64 G []float64 FDelta float64 FDeltaBound float64 GNorm float64 GNormBound float64 }
OptimizationIterationInformation is a container for information about an optimization iteration.
func (*OptimizationIterationInformation) Header ¶
func (oii *OptimizationIterationInformation) Header() string
Header returns a string with descriptions for the fields returned by String().
func (*OptimizationIterationInformation) String ¶
func (oii *OptimizationIterationInformation) String() string
String formats the iteration information fields as a row in a table.
type OptimizationIterationLogger ¶
type OptimizationIterationLogger func(info *OptimizationIterationInformation)
OptimizationIterationLogger is the type of function that logs/records/processes information about a single iteration in an optimization run.
type OptimizationStatistics ¶
type OptimizationStatistics struct { Iterations int FunctionEvaluations int GradientEvaluations int }
OptimizationStatistics is a container for basic statistics about an optimization run. Values can be negative to indicate they were not tracked.
type OptimizationStatisticser ¶
type OptimizationStatisticser interface {
OptimizationStatistics() OptimizationStatistics
}
OptimizationStatisticser is an object that can supply statistics about an optimization run.
type PointValueGradient ¶
PointValueGradient is a point in optimization space as well as the result of optimization: a point (x), its function value (f), and its gradient (g). The lengths of X and G must agree.
Directories ¶
Path | Synopsis |
---|---|
Install go-lbfgsb and build by running the following commands from this directory: $ go get -d github.com/afbarnard/go-lbfgsb $ pushd ~/go-pkgs/src/github.com/afbarnard/go-lbfgsb $ make $ popd $ go get github.com/afbarnard/go-lbfgsb $ go build Then run.
|
Install go-lbfgsb and build by running the following commands from this directory: $ go get -d github.com/afbarnard/go-lbfgsb $ pushd ~/go-pkgs/src/github.com/afbarnard/go-lbfgsb $ make $ popd $ go get github.com/afbarnard/go-lbfgsb $ go build Then run. |