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

Commit 2371855

Browse files
committedNov 10, 2015
Reduce implementation comments in CG
1 parent 6c5c19c commit 2371855

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed
 

‎cg.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,20 @@ func (cg *CG) NextDirection(loc *Location, dir []float64) (stepSize float64) {
158158

159159
cg.iterFromRestart++
160160
var restart bool
161-
// Check if the method should be restarted because too many iterations have
162-
// been taken without a restart.
163161
if cg.iterFromRestart == cg.restartAfter {
162+
// Restart because too many iterations have been taken without a restart.
164163
restart = true
165164
}
166-
// Check if the method should be restarted because the angle between
167-
// the last two gradients is too large.
165+
168166
gDot := floats.Dot(loc.Gradient, cg.gradPrev)
169167
gNorm := floats.Norm(loc.Gradient, 2)
170168
if gDot <= cg.AngleRestartThreshold*gNorm*cg.gradPrevNorm {
169+
// Restart because the angle between the last two gradients is too large.
171170
restart = true
172171
}
173172

174-
// Compute the scaling factor β_k according to the given CG variant. Do
175-
// this even when restarting, because cg.Variant may be keeping an inner
176-
// state that needs to be updated at every iteration.
173+
// Compute the scaling factor β_k even when restarting, because cg.Variant
174+
// may be keeping an inner state that needs to be updated at every iteration.
177175
beta := cg.Variant.Beta(loc.Gradient, cg.gradPrev, cg.dirPrev)
178176
if beta == 0 {
179177
// β_k == 0 means that the steepest descent direction will be taken, so
@@ -191,7 +189,7 @@ func (cg *CG) NextDirection(loc *Location, dir []float64) (stepSize float64) {
191189
}
192190
}
193191

194-
// Get the initial line search step size from the StepSizer, even if the
192+
// Get the initial line search step size from the StepSizer even if the
195193
// method was restarted, because StepSizers need to see every iteration.
196194
stepSize = cg.InitialStep.StepSize(loc, dir)
197195
if restart {

0 commit comments

Comments
 (0)