diff --git a/optimize/backtracking.go b/optimize/backtracking.go index 9454be77..2ab44e44 100644 --- a/optimize/backtracking.go +++ b/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. diff --git a/optimize/bfgs.go b/optimize/bfgs.go index 97dfdd76..4ab6d204 100644 --- a/optimize/bfgs.go +++ b/optimize/bfgs.go @@ -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 diff --git a/optimize/bisection.go b/optimize/bisection.go index bce441fc..b194a209 100644 --- a/optimize/bisection.go +++ b/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 diff --git a/optimize/cg.go b/optimize/cg.go index 04746235..9bf88c58 100644 --- a/optimize/cg.go +++ b/optimize/cg.go @@ -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 diff --git a/optimize/cmaes.go b/optimize/cmaes.go index ba755bfd..ce0b86cd 100644 --- a/optimize/cmaes.go +++ b/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. diff --git a/optimize/functionconvergence.go b/optimize/functionconvergence.go index 1bde78f9..7f987cfc 100644 --- a/optimize/functionconvergence.go +++ b/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{} diff --git a/optimize/gradientdescent.go b/optimize/gradientdescent.go index d9a9d4cd..d1189659 100644 --- a/optimize/gradientdescent.go +++ b/optimize/gradientdescent.go @@ -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 diff --git a/optimize/lbfgs.go b/optimize/lbfgs.go index 588a1523..6caad9c3 100644 --- a/optimize/lbfgs.go +++ b/optimize/lbfgs.go @@ -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 diff --git a/optimize/morethuente.go b/optimize/morethuente.go index a8cac5e7..ed6fcecd 100644 --- a/optimize/morethuente.go +++ b/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). // diff --git a/optimize/newton.go b/optimize/newton.go index 927dae4c..794b2685 100644 --- a/optimize/newton.go +++ b/optimize/newton.go @@ -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 diff --git a/optimize/printer.go b/optimize/printer.go index f4f79b02..c4cc77bc 100644 --- a/optimize/printer.go +++ b/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 { diff --git a/optimize/stepsizers.go b/optimize/stepsizers.go index c6a58c0d..fd1faf5d 100644 --- a/optimize/stepsizers.go +++ b/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 {