diff --git a/optimize/bfgs.go b/optimize/bfgs.go index e7280b28..eaef7e31 100644 --- a/optimize/bfgs.go +++ b/optimize/bfgs.go @@ -54,7 +54,7 @@ func (b *BFGS) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask, return } -func (b *BFGS) Init(loc *Location) (Operation, error) { +func (b *BFGS) initLocal(loc *Location) (Operation, error) { if b.Linesearcher == nil { b.Linesearcher = &Bisection{} } @@ -67,7 +67,7 @@ func (b *BFGS) Init(loc *Location) (Operation, error) { 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) } diff --git a/optimize/cg.go b/optimize/cg.go index ff6ef88f..f5295d4a 100644 --- a/optimize/cg.go +++ b/optimize/cg.go @@ -117,7 +117,7 @@ func (cg *CG) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask, t return } -func (cg *CG) Init(loc *Location) (Operation, error) { +func (cg *CG) initLocal(loc *Location) (Operation, error) { if cg.IterationRestartFactor < 0 { panic("cg: IterationRestartFactor is negative") } @@ -151,7 +151,7 @@ func (cg *CG) Init(loc *Location) (Operation, error) { 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) } diff --git a/optimize/gradientdescent.go b/optimize/gradientdescent.go index 0e157cd2..1eca92b5 100644 --- a/optimize/gradientdescent.go +++ b/optimize/gradientdescent.go @@ -38,7 +38,7 @@ func (g *GradientDescent) RunGlobal(operation chan<- GlobalTask, result <-chan G return } -func (g *GradientDescent) Init(loc *Location) (Operation, error) { +func (g *GradientDescent) initLocal(loc *Location) (Operation, error) { if g.Linesearcher == nil { g.Linesearcher = &Backtracking{} } @@ -55,7 +55,7 @@ func (g *GradientDescent) Init(loc *Location) (Operation, error) { 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) } diff --git a/optimize/interfaces.go b/optimize/interfaces.go index 2c7d6e00..b6d1b9b1 100644 --- a/optimize/interfaces.go +++ b/optimize/interfaces.go @@ -4,7 +4,7 @@ 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 // 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 // reserved for the clients to be passed to Recorders. A Method must also not // 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 // and returns the first operation to be carried out by the caller. // 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, // updates loc and returns the next operation. - Iterate(loc *Location) (Operation, error) + iterateLocal(loc *Location) (Operation, error) Needser } diff --git a/optimize/lbfgs.go b/optimize/lbfgs.go index 52200f94..5e30bc67 100644 --- a/optimize/lbfgs.go +++ b/optimize/lbfgs.go @@ -60,7 +60,7 @@ func (l *LBFGS) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask, return } -func (l *LBFGS) Init(loc *Location) (Operation, error) { +func (l *LBFGS) initLocal(loc *Location) (Operation, error) { if l.Linesearcher == nil { l.Linesearcher = &Bisection{} } @@ -77,7 +77,7 @@ func (l *LBFGS) Init(loc *Location) (Operation, error) { 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) } diff --git a/optimize/local.go b/optimize/local.go index 4e8f5ce9..136157fb 100644 --- a/optimize/local.go +++ b/optimize/local.go @@ -11,11 +11,11 @@ import ( // localOptimizer is a helper type for running an optimization using a LocalMethod. 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 // provides a happens before relationship between the return of status and the // 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. task := tasks[0] task = l.initialLocation(operation, result, task, method) @@ -38,7 +38,7 @@ func (l localOptimizer) runGlobal(method Method, operation chan<- GlobalTask, re return NotTerminated, nil } - op, err := method.Init(task.Location) + op, err := method.initLocal(task.Location) if err != nil { l.finishMethodDone(operation, result, task) return Failure, err @@ -52,7 +52,7 @@ Loop: case PostIteration: break Loop default: - op, err := method.Iterate(r.Location) + op, err := method.iterateLocal(r.Location) if err != nil { l.finishMethodDone(operation, result, r) return Failure, err diff --git a/optimize/neldermead.go b/optimize/neldermead.go index c1d7ce29..fe460741 100644 --- a/optimize/neldermead.go +++ b/optimize/neldermead.go @@ -101,7 +101,7 @@ func (n *NelderMead) RunGlobal(operation chan<- GlobalTask, result <-chan Global return } -func (n *NelderMead) Init(loc *Location) (Operation, error) { +func (n *NelderMead) initLocal(loc *Location) (Operation, error) { dim := len(loc.X) if cap(n.vertices) < 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) switch n.lastIter { case nmInitialize: diff --git a/optimize/newton.go b/optimize/newton.go index 530f64da..5b78c465 100644 --- a/optimize/newton.go +++ b/optimize/newton.go @@ -72,7 +72,7 @@ func (n *Newton) RunGlobal(operation chan<- GlobalTask, result <-chan GlobalTask return } -func (n *Newton) Init(loc *Location) (Operation, error) { +func (n *Newton) initLocal(loc *Location) (Operation, error) { if n.Increase == 0 { n.Increase = 5 } @@ -91,7 +91,7 @@ func (n *Newton) Init(loc *Location) (Operation, error) { 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) }