Change Method to localMethod.

Now that Local is gone, unexport the type.
This commit is contained in:
Brendan Tracey
2018-07-18 13:16:48 -06:00
parent 72e79ca985
commit 3dd933ac47
8 changed files with 20 additions and 20 deletions

View File

@@ -54,7 +54,7 @@ func (b *BFGS) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask,
return return
} }
func (b *BFGS) Init(loc *Location) (Operation, error) { func (b *BFGS) initLocal(loc *Location) (Operation, error) {
if b.Linesearcher == nil { if b.Linesearcher == nil {
b.Linesearcher = &Bisection{} b.Linesearcher = &Bisection{}
} }
@@ -67,7 +67,7 @@ func (b *BFGS) Init(loc *Location) (Operation, error) {
return b.ls.Init(loc) return b.ls.Init(loc)
} }
func (b *BFGS) Iterate(loc *Location) (Operation, error) { func (b *BFGS) iterateLocal(loc *Location) (Operation, error) {
return b.ls.Iterate(loc) return b.ls.Iterate(loc)
} }

View File

@@ -117,7 +117,7 @@ func (cg *CG) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask, t
return return
} }
func (cg *CG) Init(loc *Location) (Operation, error) { func (cg *CG) initLocal(loc *Location) (Operation, error) {
if cg.IterationRestartFactor < 0 { if cg.IterationRestartFactor < 0 {
panic("cg: IterationRestartFactor is negative") panic("cg: IterationRestartFactor is negative")
} }
@@ -151,7 +151,7 @@ func (cg *CG) Init(loc *Location) (Operation, error) {
return cg.ls.Init(loc) return cg.ls.Init(loc)
} }
func (cg *CG) Iterate(loc *Location) (Operation, error) { func (cg *CG) iterateLocal(loc *Location) (Operation, error) {
return cg.ls.Iterate(loc) return cg.ls.Iterate(loc)
} }

View File

@@ -38,7 +38,7 @@ func (g *GradientDescent) RunGlobal(operation chan<- GlobalTask, result <-chan G
return return
} }
func (g *GradientDescent) Init(loc *Location) (Operation, error) { func (g *GradientDescent) initLocal(loc *Location) (Operation, error) {
if g.Linesearcher == nil { if g.Linesearcher == nil {
g.Linesearcher = &Backtracking{} g.Linesearcher = &Backtracking{}
} }
@@ -55,7 +55,7 @@ func (g *GradientDescent) Init(loc *Location) (Operation, error) {
return g.ls.Init(loc) return g.ls.Init(loc)
} }
func (g *GradientDescent) Iterate(loc *Location) (Operation, error) { func (g *GradientDescent) iterateLocal(loc *Location) (Operation, error) {
return g.ls.Iterate(loc) return g.ls.Iterate(loc)
} }

View File

@@ -4,7 +4,7 @@
package optimize package optimize
// A Method can optimize an objective function. // A localMethod can optimize an objective function.
// //
// It uses a reverse-communication interface between the optimization method // It uses a reverse-communication interface between the optimization method
// and the caller. Method acts as a client that asks the caller to perform // and the caller. Method acts as a client that asks the caller to perform
@@ -34,15 +34,15 @@ package optimize
// A Method must not return InitIteration and PostIteration operations. These are // A Method must not return InitIteration and PostIteration operations. These are
// reserved for the clients to be passed to Recorders. A Method must also not // reserved for the clients to be passed to Recorders. A Method must also not
// combine the Evaluation operations with the Iteration operations. // combine the Evaluation operations with the Iteration operations.
type Method interface { type localMethod interface {
// Init initializes the method based on the initial data in loc, updates it // 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. // 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) initLocal(loc *Location) (Operation, error)
// Iterate retrieves data from loc, performs one iteration of the method, // Iterate retrieves data from loc, performs one iteration of the method,
// updates loc and returns the next operation. // updates loc and returns the next operation.
Iterate(loc *Location) (Operation, error) iterateLocal(loc *Location) (Operation, error)
Needser Needser
} }

View File

@@ -60,7 +60,7 @@ func (l *LBFGS) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask,
return return
} }
func (l *LBFGS) Init(loc *Location) (Operation, error) { func (l *LBFGS) initLocal(loc *Location) (Operation, error) {
if l.Linesearcher == nil { if l.Linesearcher == nil {
l.Linesearcher = &Bisection{} l.Linesearcher = &Bisection{}
} }
@@ -77,7 +77,7 @@ func (l *LBFGS) Init(loc *Location) (Operation, error) {
return l.ls.Init(loc) return l.ls.Init(loc)
} }
func (l *LBFGS) Iterate(loc *Location) (Operation, error) { func (l *LBFGS) iterateLocal(loc *Location) (Operation, error) {
return l.ls.Iterate(loc) return l.ls.Iterate(loc)
} }

View File

@@ -11,11 +11,11 @@ import (
// localOptimizer is a helper type for running an optimization using a LocalMethod. // localOptimizer is a helper type for running an optimization using a LocalMethod.
type localOptimizer struct{} type localOptimizer struct{}
// RunGlobal controls the optimization run for a LocalMethod. The calling method // RunGlobal controls the optimization run for a localMethod. The calling method
// must close the operation channel at the conclusion of the optimization. This // must close the operation channel at the conclusion of the optimization. This
// provides a happens before relationship between the return of status and the // provides a happens before relationship between the return of status and the
// closure of operation, and thus a call to method.Status (if necessary). // closure of operation, and thus a call to method.Status (if necessary).
func (l localOptimizer) runGlobal(method Method, operation chan<- GlobalTask, result <-chan GlobalTask, tasks []GlobalTask) (Status, error) { func (l localOptimizer) runGlobal(method localMethod, operation chan<- GlobalTask, result <-chan GlobalTask, tasks []GlobalTask) (Status, error) {
// Local methods start with a fully-specified initial location. // Local methods start with a fully-specified initial location.
task := tasks[0] task := tasks[0]
task = l.initialLocation(operation, result, task, method) task = l.initialLocation(operation, result, task, method)
@@ -38,7 +38,7 @@ func (l localOptimizer) runGlobal(method Method, operation chan<- GlobalTask, re
return NotTerminated, nil return NotTerminated, nil
} }
op, err := method.Init(task.Location) op, err := method.initLocal(task.Location)
if err != nil { if err != nil {
l.finishMethodDone(operation, result, task) l.finishMethodDone(operation, result, task)
return Failure, err return Failure, err
@@ -52,7 +52,7 @@ Loop:
case PostIteration: case PostIteration:
break Loop break Loop
default: default:
op, err := method.Iterate(r.Location) op, err := method.iterateLocal(r.Location)
if err != nil { if err != nil {
l.finishMethodDone(operation, result, r) l.finishMethodDone(operation, result, r)
return Failure, err return Failure, err

View File

@@ -101,7 +101,7 @@ func (n *NelderMead) RunGlobal(operation chan<- GlobalTask, result <-chan Global
return return
} }
func (n *NelderMead) Init(loc *Location) (Operation, error) { func (n *NelderMead) initLocal(loc *Location) (Operation, error) {
dim := len(loc.X) dim := len(loc.X)
if cap(n.vertices) < dim+1 { if cap(n.vertices) < dim+1 {
n.vertices = make([][]float64, dim+1) n.vertices = make([][]float64, dim+1)
@@ -194,7 +194,7 @@ func computeCentroid(vertices [][]float64, centroid []float64) {
} }
} }
func (n *NelderMead) Iterate(loc *Location) (Operation, error) { func (n *NelderMead) iterateLocal(loc *Location) (Operation, error) {
dim := len(loc.X) dim := len(loc.X)
switch n.lastIter { switch n.lastIter {
case nmInitialize: case nmInitialize:

View File

@@ -72,7 +72,7 @@ func (n *Newton) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask
return return
} }
func (n *Newton) Init(loc *Location) (Operation, error) { func (n *Newton) initLocal(loc *Location) (Operation, error) {
if n.Increase == 0 { if n.Increase == 0 {
n.Increase = 5 n.Increase = 5
} }
@@ -91,7 +91,7 @@ func (n *Newton) Init(loc *Location) (Operation, error) {
return n.ls.Init(loc) return n.ls.Init(loc)
} }
func (n *Newton) Iterate(loc *Location) (Operation, error) { func (n *Newton) iterateLocal(loc *Location) (Operation, error) {
return n.ls.Iterate(loc) return n.ls.Iterate(loc)
} }