optimize: explicitly state interface satisfaction of types
MODIFY
optimize/backtracking.go
optimize/backtracking.go
@@ -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.

MODIFY
optimize/bisection.go
optimize/bisection.go
@@ -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

MODIFY
optimize/cmaes.go
optimize/cmaes.go
@@ -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.

MODIFY
optimize/functionconvergence.go
optimize/functionconvergence.go
@@ -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{}

MODIFY
optimize/gradientdescent.go
optimize/gradientdescent.go
@@ -9,6 +9,7 @@ import "gonum.org/v1/gonum/floats"
var (
_ Method = (*GradientDescent)(nil)
_ localMethod = (*GradientDescent)(nil)
+ _ NextDirectioner = (*GradientDescent)(nil)
)
// GradientDescent implements the steepest descent optimization method that

MODIFY
optimize/lbfgs.go
optimize/lbfgs.go
@@ -11,6 +11,7 @@ import (
var (
_ Method = (*LBFGS)(nil)
_ localMethod = (*LBFGS)(nil)
+ _ NextDirectioner = (*LBFGS)(nil)
)
// LBFGS implements the limited-memory BFGS method for gradient-based

MODIFY
optimize/morethuente.go
optimize/morethuente.go
@@ -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).
//

MODIFY
optimize/newton.go
optimize/newton.go
@@ -15,6 +15,7 @@ const maxNewtonModifications = 20
var (
_ Method = (*Newton)(nil)
_ localMethod = (*Newton)(nil)
+ _ NextDirectioner = (*Newton)(nil)
)
// Newton implements a modified Newton's method for Hessian-based unconstrained

MODIFY
optimize/printer.go
optimize/printer.go
@@ -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 {

MODIFY
optimize/stepsizers.go
optimize/stepsizers.go
@@ -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 {

optimize: explicitly state interface satisfaction of types