mirror of
https://github.com/gonum/gonum.git
synced 2025-09-26 19:21:17 +08:00
optimize: explicitly state interface satisfaction of types
This commit is contained in:
@@ -10,6 +10,8 @@ const (
|
||||
minimumBacktrackingStepSize = 1e-20
|
||||
)
|
||||
|
||||
var _ Linesearcher = (*Backtracking)(nil)
|
||||
|
||||
// Backtracking is a Linesearcher that uses backtracking to find a point that
|
||||
// satisfies the Armijo condition with the given decrease factor. If the Armijo
|
||||
// condition has not been met, the step size is decreased by ContractionFactor.
|
||||
|
@@ -11,8 +11,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ Method = (*BFGS)(nil)
|
||||
_ localMethod = (*BFGS)(nil)
|
||||
_ Method = (*BFGS)(nil)
|
||||
_ localMethod = (*BFGS)(nil)
|
||||
_ NextDirectioner = (*BFGS)(nil)
|
||||
)
|
||||
|
||||
// BFGS implements the Broyden–Fletcher–Goldfarb–Shanno optimization method. It
|
||||
|
@@ -6,9 +6,9 @@ package optimize
|
||||
|
||||
import "math"
|
||||
|
||||
const (
|
||||
defaultBisectionCurvature = 0.9
|
||||
)
|
||||
const defaultBisectionCurvature = 0.9
|
||||
|
||||
var _ Linesearcher = (*Bisection)(nil)
|
||||
|
||||
// Bisection is a Linesearcher that uses a bisection to find a point that
|
||||
// satisfies the strong Wolfe conditions with the given curvature factor and
|
||||
|
@@ -16,8 +16,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
_ Method = (*CG)(nil)
|
||||
_ localMethod = (*CG)(nil)
|
||||
_ Method = (*CG)(nil)
|
||||
_ localMethod = (*CG)(nil)
|
||||
_ NextDirectioner = (*CG)(nil)
|
||||
)
|
||||
|
||||
// CGVariant calculates the scaling parameter, β, used for updating the
|
||||
@@ -31,6 +32,14 @@ type CGVariant interface {
|
||||
Beta(grad, gradPrev, dirPrev []float64) float64
|
||||
}
|
||||
|
||||
var (
|
||||
_ CGVariant = (*FletcherReeves)(nil)
|
||||
_ CGVariant = (*PolakRibierePolyak)(nil)
|
||||
_ CGVariant = (*HestenesStiefel)(nil)
|
||||
_ CGVariant = (*DaiYuan)(nil)
|
||||
_ CGVariant = (*HagerZhang)(nil)
|
||||
)
|
||||
|
||||
// CG implements the nonlinear conjugate gradient method for solving nonlinear
|
||||
// unconstrained optimization problems. It is a line search method that
|
||||
// generates the search directions d_k according to the formula
|
||||
|
@@ -15,6 +15,8 @@ import (
|
||||
"gonum.org/v1/gonum/stat/distmv"
|
||||
)
|
||||
|
||||
var _ Method = (*CmaEsChol)(nil)
|
||||
|
||||
// TODO(btracey): If we ever implement the traditional CMA-ES algorithm, provide
|
||||
// the base explanation there, and modify this description to just
|
||||
// describe the differences.
|
||||
|
@@ -16,6 +16,11 @@ type Converger interface {
|
||||
Converged(loc *Location) Status
|
||||
}
|
||||
|
||||
var (
|
||||
_ Converger = NeverTerminate{}
|
||||
_ Converger = (*FunctionConverge)(nil)
|
||||
)
|
||||
|
||||
// NeverTerminate implements Converger, always reporting NotTerminated.
|
||||
type NeverTerminate struct{}
|
||||
|
||||
|
@@ -7,8 +7,9 @@ package optimize
|
||||
import "gonum.org/v1/gonum/floats"
|
||||
|
||||
var (
|
||||
_ Method = (*GradientDescent)(nil)
|
||||
_ localMethod = (*GradientDescent)(nil)
|
||||
_ Method = (*GradientDescent)(nil)
|
||||
_ localMethod = (*GradientDescent)(nil)
|
||||
_ NextDirectioner = (*GradientDescent)(nil)
|
||||
)
|
||||
|
||||
// GradientDescent implements the steepest descent optimization method that
|
||||
|
@@ -9,8 +9,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ Method = (*LBFGS)(nil)
|
||||
_ localMethod = (*LBFGS)(nil)
|
||||
_ Method = (*LBFGS)(nil)
|
||||
_ localMethod = (*LBFGS)(nil)
|
||||
_ NextDirectioner = (*LBFGS)(nil)
|
||||
)
|
||||
|
||||
// LBFGS implements the limited-memory BFGS method for gradient-based
|
||||
|
@@ -6,6 +6,8 @@ package optimize
|
||||
|
||||
import "math"
|
||||
|
||||
var _ Linesearcher = (*MoreThuente)(nil)
|
||||
|
||||
// MoreThuente is a Linesearcher that finds steps that satisfy both the
|
||||
// sufficient decrease and curvature conditions (the strong Wolfe conditions).
|
||||
//
|
||||
|
@@ -13,8 +13,9 @@ import (
|
||||
const maxNewtonModifications = 20
|
||||
|
||||
var (
|
||||
_ Method = (*Newton)(nil)
|
||||
_ localMethod = (*Newton)(nil)
|
||||
_ Method = (*Newton)(nil)
|
||||
_ localMethod = (*Newton)(nil)
|
||||
_ NextDirectioner = (*Newton)(nil)
|
||||
)
|
||||
|
||||
// Newton implements a modified Newton's method for Hessian-based unconstrained
|
||||
|
@@ -30,6 +30,8 @@ const (
|
||||
printerHessTmpl = " %9v" // Appended to base template when loc.Hessian != nil.
|
||||
)
|
||||
|
||||
var _ Recorder = (*Printer)(nil)
|
||||
|
||||
// Printer writes column-format output to the specified writer as the optimization
|
||||
// progresses. By default, it writes to os.Stdout.
|
||||
type Printer struct {
|
||||
|
@@ -21,6 +21,12 @@ const (
|
||||
firstOrderMaximumStepSize = quadraticMaximumStepSize
|
||||
)
|
||||
|
||||
var (
|
||||
_ StepSizer = ConstantStepSize{}
|
||||
_ StepSizer = (*QuadraticStepSize)(nil)
|
||||
_ StepSizer = (*FirstOrderStepSize)(nil)
|
||||
)
|
||||
|
||||
// ConstantStepSize is a StepSizer that returns the same step size for
|
||||
// every iteration.
|
||||
type ConstantStepSize struct {
|
||||
|
Reference in New Issue
Block a user