Skip to content
This repository was archived by the owner on Nov 23, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CGVariant interface {
// - The angle between the gradients at two consecutive iterations ∇f_k and
// ∇f_{k+1} is too large.
// - The direction d_{k+1} is not a descent direction.
// - β_k given by CGVariant.Beta() is equal to zero.
// - β_k returned from CGVariant.Beta is equal to zero.
//
// The line search for CG must yield step sizes that satisfy the strong Wolfe
// conditions at every iteration, otherwise the generated search direction
Expand Down
4 changes: 2 additions & 2 deletions functions/minsurf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestMinimalSurface(t *testing.T) {
}

// Test that the gradient at the minimum is small enough.
// In some sense this test is not completely correct because ExactX()
// is the exact solution to the continuous problem projected on the
// In some sense this test is not completely correct because ExactX
// returns the exact solution to the continuous problem projected on the
// grid, not the exact solution to the discrete problem which we are
// solving. This is the reason why a relatively loose tolerance 1e-4
// must be used.
Expand Down
8 changes: 4 additions & 4 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ package optimize
type Method interface {
// Init initializes the method based on the initial data in loc, updates it
// and returns the first operation to be carried out by the caller.
// The initial location must be valid as specified by Needs().
// The initial location must be valid as specified by Needs.
Init(loc *Location) (Operation, error)

// Iterate retrieves data from loc, performs one iteration of the method,
// updates loc and returns the next operation.
// TODO(vladimir-ch): When decided, say something whether the contents of
// Location is preserved between calls to Iterate().
// Location is preserved between calls to Iterate.
Iterate(loc *Location) (Operation, error)

// Needs specifies information about the objective function needed by the
// optimizer beyond just the function value. The information is used
// internally for initialization and must match evaluation types returned
// by Init() and Iterate() during the optimization process.
// by Init and Iterate during the optimization process.
Needs() struct {
Gradient bool
Hessian bool
Expand All @@ -52,7 +52,7 @@ type Method interface {

// Statuser can report the status and any error. It is intended for methods as
// an additional error reporting mechanism apart from the errors returned from
// Init() and Iterate().
// Init and Iterate.
type Statuser interface {
Status() (Status, error)
}
Expand Down
8 changes: 4 additions & 4 deletions linesearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ type LinesearchMethod struct {
dir []float64 // Search direction for the current iteration.

first bool // Indicator of the first iteration.
nextMajor bool // Indicates that MajorIteration must be requested at the next call to Iterate().
nextMajor bool // Indicates that MajorIteration must be requested at the next call to Iterate.

loc Location // Storage for intermediate locations.
eval Operation // Indicator of valid fields in loc.

lastStep float64 // Step taken from x in the previous call to Iterate().
lastOp Operation // Operation returned from the previous call to Iterate().
lastStep float64 // Step taken from x in the previous call to Iterate.
lastOp Operation // Operation returned from the previous call to Iterate.
}

func (ls *LinesearchMethod) Init(loc *Location) (Operation, error) {
Expand Down Expand Up @@ -60,7 +60,7 @@ func (ls *LinesearchMethod) Iterate(loc *Location) (Operation, error) {
switch ls.lastOp {
case NoOperation:
// TODO(vladimir-ch): We have previously returned with an error and
// Init() was not called. What to do? What about ls's internal state?
// Init was not called. What to do? What about ls's internal state?

case MajorIteration:
// We previously requested MajorIteration but since we're here, the
Expand Down
14 changes: 7 additions & 7 deletions local.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// routines that evaluate the objective function, gradient, and other
// quantities related to the problem. The objective function, p.Func, must not
// be nil. The optimization method used may require other fields to be non-nil
// as specified by method.Needs(). Local will panic if these are not met. The
// as specified by method.Needs. Local will panic if these are not met. The
// method can be determined automatically from the supplied problem which is
// described below.
//
Expand All @@ -34,7 +34,7 @@ import (
// problem dimension.
//
// The third argument contains the settings for the minimization. It is here that
// gradient tolerance, etc. are specified. The DefaultSettings() function
// gradient tolerance, etc. are specified. The DefaultSettings function
// can be called for a Settings struct with the default values initialized.
// If settings == nil, the default settings are used. See the documentation
// for the Settings structure for more information. The optimization Method used
Expand All @@ -50,8 +50,8 @@ import (
// in the method will be populated with default values. The methods are also
// designed such that they can be reused in future calls to Local.
//
// If method implements Statuser, method.Status() is called before every call
// to method.Iterate(). If the returned Status is not NotTerminated or the
// If method implements Statuser, method.Status is called before every call
// to method.Iterate. If the returned Status is not NotTerminated or the
// error is non-nil, the optimization run is terminated.
//
// Local returns a Result struct and any error that occurred. See the
Expand Down Expand Up @@ -151,7 +151,7 @@ func minimize(p *Problem, method Method, settings *Settings, stats *Stats, optLo
}

for {
// Sequentially call method.Iterate(), performing the operations it has
// Sequentially call method.Iterate, performing the operations it has
// requested, until convergence.

switch op {
Expand Down Expand Up @@ -311,7 +311,7 @@ func getStartingLocation(p *Problem, method Method, initX []float64, stats *Stat
// checkConvergence returns NotTerminated if the Location does not satisfy the
// convergence criteria given by settings. Otherwise a corresponding status is
// returned.
// Unlike checkLimits, it is called by Local() only at MajorIterations.
// Unlike checkLimits, checkConvergence is called by Local only at MajorIterations.
func checkConvergence(loc *Location, settings *Settings) Status {
if loc.Gradient != nil {
norm := floats.Norm(loc.Gradient, math.Inf(1))
Expand All @@ -333,7 +333,7 @@ func checkConvergence(loc *Location, settings *Settings) Status {

// checkLimits returns NotTerminated status if the various limits given by
// settings has not been reached. Otherwise it returns a corresponding status.
// Unlike checkConvergence(), it is called by Local() at _every_ iteration.
// Unlike checkConvergence, checkLimits is called by Local at _every_ iteration.
func checkLimits(loc *Location, stats *Stats, settings *Settings) Status {
// Check the objective function value for negative infinity because it
// could break the linesearches and -inf is the best we can do anyway.
Expand Down
2 changes: 1 addition & 1 deletion termination.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var statuses = []struct {
// calls to NewStatus are not thread safe.
//
// NewStatus takes in three arguments, the string that should be output from
// Status.String(), a boolean if the status indicates early optimization conclusion,
// Status.String, a boolean if the status indicates early optimization conclusion,
// and the error to return from Err (if any).
func NewStatus(name string, early bool, err error) Status {
statuses = append(statuses, struct {
Expand Down
14 changes: 7 additions & 7 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ type Result struct {
// Stats contains the statistics of the run.
type Stats struct {
MajorIterations int // Total number of major iterations
FuncEvaluations int // Number of evaluations of Func()
GradEvaluations int // Number of evaluations of Grad()
HessEvaluations int // Number of evaluations of Hess()
FuncEvaluations int // Number of evaluations of Func
GradEvaluations int // Number of evaluations of Grad
HessEvaluations int // Number of evaluations of Hess
Runtime time.Duration // Total runtime of the optimization
}

Expand Down Expand Up @@ -154,7 +154,7 @@ func (p Problem) satisfies(method Method) error {

// Settings represents settings of the optimization run. It contains initial
// settings, convergence information, and Recorder information. In general, users
// should use DefaultSettings() rather than constructing a Settings literal.
// should use DefaultSettings rather than constructing a Settings literal.
//
// If UseInitData is true, InitialValue, InitialGradient and InitialHessian
// specify function information at the initial location.
Expand Down Expand Up @@ -208,21 +208,21 @@ type Settings struct {

// FuncEvaluations is the maximum allowed number of function evaluations.
// FunctionEvaluationLimit status is returned if the total number of calls
// to Func() equals or exceeds this number.
// to Func equals or exceeds this number.
// If it equals zero, this setting has no effect.
// The default value is 0.
FuncEvaluations int

// GradEvaluations is the maximum allowed number of gradient evaluations.
// GradientEvaluationLimit status is returned if the total number of calls
// to Grad() equals or exceeds this number.
// to Grad equals or exceeds this number.
// If it equals zero, this setting has no effect.
// The default value is 0.
GradEvaluations int

// HessEvaluations is the maximum allowed number of Hessian evaluations.
// HessianEvaluationLimit status is returned if the total number of calls
// to Hess() equals or exceeds this number.
// to Hess equals or exceeds this number.
// If it equals zero, this setting has no effect.
// The default value is 0.
HessEvaluations int
Expand Down
6 changes: 3 additions & 3 deletions unconstrained_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type unconstrainedTest struct {
// the default value of 20 will be used.
fIter int
// long indicates that the test takes long time to finish and will be
// excluded if testing.Short() is true.
// excluded if testing.Short returns true.
long bool
}

Expand Down Expand Up @@ -995,15 +995,15 @@ func newVariablyDimensioned(dim int, gradTol float64) unconstrainedTest {

func TestLocal(t *testing.T) {
var tests []unconstrainedTest
// Mix of functions with and without Grad() method.
// Mix of functions with and without Grad method.
tests = append(tests, gradFreeTests...)
tests = append(tests, gradientDescentTests...)
testLocal(t, gradientDescentTests, nil)
}

func TestNelderMead(t *testing.T) {
var tests []unconstrainedTest
// Mix of functions with and without Grad() method.
// Mix of functions with and without Grad method.
tests = append(tests, gradFreeTests...)
tests = append(tests, gradientDescentTests...)
testLocal(t, tests, &NelderMead{})
Expand Down