Skip to content
This repository was archived by the owner on Nov 23, 2018. It is now read-only.

Commit a0582c6

Browse files
committed
Remove unnecessary ProblemInfo
1 parent 16b97c0 commit a0582c6

File tree

12 files changed

+19
-35
lines changed

12 files changed

+19
-35
lines changed

backtracking.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Backtracking struct {
3232
initG float64
3333
}
3434

35-
func (b *Backtracking) Init(loc LinesearchLocation, step float64, _ *ProblemInfo) EvaluationType {
35+
func (b *Backtracking) Init(loc LinesearchLocation, step float64) EvaluationType {
3636
if step <= 0 {
3737
panic("backtracking: bad step size")
3838
}

bfgs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type BFGS struct {
4141
// NOTE: This method exists so that it's easier to use a bfgs algorithm because
4242
// it implements Method
4343

44-
func (b *BFGS) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationType, IterationType, error) {
44+
func (b *BFGS) Init(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {
4545
if b.LinesearchMethod == nil {
4646
b.LinesearchMethod = &Bisection{}
4747
}
@@ -51,7 +51,7 @@ func (b *BFGS) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationT
5151
b.linesearch.Method = b.LinesearchMethod
5252
b.linesearch.NextDirectioner = b
5353

54-
return b.linesearch.Init(loc, p, xNext)
54+
return b.linesearch.Init(loc, xNext)
5555
}
5656

5757
func (b *BFGS) Iterate(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {

bisection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Bisection struct {
2626
maxGrad float64
2727
}
2828

29-
func (b *Bisection) Init(loc LinesearchLocation, step float64, _ *ProblemInfo) EvaluationType {
29+
func (b *Bisection) Init(loc LinesearchLocation, step float64) EvaluationType {
3030
if loc.Derivative >= 0 {
3131
panic("bisection: init G non-negative")
3232
}

cg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type CG struct {
9494
gradPrevNorm float64
9595
}
9696

97-
func (cg *CG) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationType, IterationType, error) {
97+
func (cg *CG) Init(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {
9898
if cg.IterationRestartFactor < 0 {
9999
panic("cg: IterationRestartFactor is negative")
100100
}
@@ -125,7 +125,7 @@ func (cg *CG) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationTy
125125
cg.linesearch.Method = cg.LinesearchMethod
126126
cg.linesearch.NextDirectioner = cg
127127

128-
return cg.linesearch.Init(loc, p, xNext)
128+
return cg.linesearch.Init(loc, xNext)
129129
}
130130

131131
func (cg *CG) Iterate(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {

gradientdescent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type GradientDescent struct {
1818
linesearch *Linesearch
1919
}
2020

21-
func (g *GradientDescent) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationType, IterationType, error) {
21+
func (g *GradientDescent) Init(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {
2222
if g.StepSizer == nil {
2323
g.StepSizer = &QuadraticStepSize{}
2424
}
@@ -31,7 +31,7 @@ func (g *GradientDescent) Init(loc *Location, p *ProblemInfo, xNext []float64) (
3131
g.linesearch.Method = g.LinesearchMethod
3232
g.linesearch.NextDirectioner = g
3333

34-
return g.linesearch.Init(loc, p, xNext)
34+
return g.linesearch.Init(loc, xNext)
3535
}
3636

3737
func (g *GradientDescent) Iterate(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {

interfaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type LinesearchMethod interface {
1111
// Init initializes the linesearch method. LinesearchLocation contains the
1212
// function information at step == 0, and step contains the first step length
1313
// as specified by the NextDirectioner.
14-
Init(loc LinesearchLocation, step float64, p *ProblemInfo) EvaluationType
14+
Init(loc LinesearchLocation, step float64) EvaluationType
1515

1616
// Finished takes in the function result at the most recent linesearch location,
1717
// and returns true if the line search has been concluded.
@@ -42,7 +42,7 @@ type NextDirectioner interface {
4242
// A Method can optimize an objective function.
4343
type Method interface {
4444
// Initializes the method and returns the first location to evaluate
45-
Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationType, IterationType, error)
45+
Init(loc *Location, xNext []float64) (EvaluationType, IterationType, error)
4646

4747
// Stores the next location to evaluate in xNext
4848
Iterate(loc *Location, xNext []float64) (EvaluationType, IterationType, error)

lbfgs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type LBFGS struct {
3838
rhoHist []float64 // last Store iterations of rho
3939
}
4040

41-
func (l *LBFGS) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationType, IterationType, error) {
41+
func (l *LBFGS) Init(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {
4242
if l.LinesearchMethod == nil {
4343
l.LinesearchMethod = &Bisection{}
4444
}
@@ -47,7 +47,7 @@ func (l *LBFGS) Init(loc *Location, p *ProblemInfo, xNext []float64) (Evaluation
4747
}
4848
l.linesearch.Method = l.LinesearchMethod
4949
l.linesearch.NextDirectioner = l
50-
return l.linesearch.Init(loc, p, xNext)
50+
return l.linesearch.Init(loc, xNext)
5151
}
5252

5353
func (l *LBFGS) Iterate(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {

linesearch.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ type Linesearch struct {
2121
initX []float64
2222
dir []float64
2323

24-
probInfo *ProblemInfo
25-
2624
lastEvalType EvaluationType
2725
iterType IterationType
2826
}
2927

30-
func (ls *Linesearch) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationType, IterationType, error) {
28+
func (ls *Linesearch) Init(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {
3129
ls.initX = resize(ls.initX, len(loc.X))
3230
copy(ls.initX, loc.X)
3331

@@ -45,9 +43,8 @@ func (ls *Linesearch) Init(loc *Location, p *ProblemInfo, xNext []float64) (Eval
4543
F: loc.F,
4644
Derivative: projGrad,
4745
}
48-
evalType := ls.Method.Init(lsLoc, stepSize, p)
46+
evalType := ls.Method.Init(lsLoc, stepSize)
4947
floats.AddScaledTo(xNext, ls.initX, stepSize, ls.dir)
50-
ls.probInfo = p
5148
ls.lastEvalType = evalType
5249
ls.iterType = MinorIteration
5350
return evalType, ls.iterType, nil
@@ -120,7 +117,7 @@ func (ls *Linesearch) initNextLinesearch(loc *Location, xNext []float64) (Evalua
120117
F: loc.F,
121118
Derivative: projGrad,
122119
}
123-
evalType := ls.Method.Init(lsLoc, stepsize, ls.probInfo)
120+
evalType := ls.Method.Init(lsLoc, stepsize)
124121
floats.AddScaledTo(xNext, ls.initX, stepsize, ls.dir)
125122
// Compare the starting point for the current iteration with the next
126123
// evaluation point to make sure that rounding errors do not prevent progress.

local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func minimize(settings *Settings, method Method, p *Problem, stats *Stats, optLo
131131

132132
methodStatus, methodIsStatuser := method.(Statuser)
133133

134-
evalType, iterType, err := method.Init(loc, newProblemInfo(p), xNext)
134+
evalType, iterType, err := method.Init(loc, xNext)
135135
if err != nil {
136136
return Failure, err
137137
}

neldermead.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ type NelderMead struct {
8181
reflectedValue float64 // Value at the last reflection point
8282
}
8383

84-
func (n *NelderMead) Init(loc *Location, p *ProblemInfo, xNext []float64) (EvaluationType, IterationType, error) {
84+
func (n *NelderMead) Init(loc *Location, xNext []float64) (EvaluationType, IterationType, error) {
8585
dim := len(loc.X)
8686
if cap(n.vertices) < dim+1 {
8787
n.vertices = make([][]float64, dim+1)

0 commit comments

Comments
 (0)