5
5
package optimize
6
6
7
7
const (
8
- defaultBacktrackingDecrease = 0.5
9
- defaultBacktrackingFuncConst = 1e-4
10
- minimumBacktrackingStepSize = 1e-20
8
+ defaultBacktrackingContraction = 0.5
9
+ defaultBacktrackingDecrease = 1e-4
10
+ minimumBacktrackingStepSize = 1e-20
11
11
)
12
12
13
13
// Backtracking is a Linesearcher that uses backtracking to find a point that
14
- // satisfies the Armijo condition with the given function constant FuncConst. If
15
- // the Armijo condition has not been met, the step size is decreased by a
16
- // factor of Decrease.
14
+ // satisfies the Armijo condition with the given decrease factor. If the Armijo
15
+ // condition has not been met, the step size is decreased by ContractionFactor.
17
16
//
18
17
// The Armijo condition only requires the gradient at the beginning of each
19
18
// major iteration (not at successive step locations), and so Backtracking may
20
19
// be a good linesearch for functions with expensive gradients. Backtracking is
21
20
// not appropriate for optimizers that require the Wolfe conditions to be met,
22
21
// such as BFGS.
23
22
//
24
- // Both FuncConst and Decrease must be between zero and one, and Backtracking will
25
- // panic otherwise. If either FuncConst or Decrease are zero, it will be set to a
26
- // reasonable default.
23
+ // Both DecreaseFactor and ContractionFactor must be between zero and one, and
24
+ // Backtracking will panic otherwise. If either DecreaseFactor or
25
+ // ContractionFactor are zero, it will be set to a reasonable default.
27
26
type Backtracking struct {
28
- FuncConst float64 // Necessary function descrease for Armijo condition.
29
- Decrease float64 // Step size multiplier at each iteration (stepSize *= Decrease ).
27
+ DecreaseFactor float64 // Constant factor in the sufficient decrease ( Armijo) condition.
28
+ ContractionFactor float64 // Step size multiplier at each iteration (step *= ContractionFactor ).
30
29
31
30
stepSize float64
32
31
initF float64
@@ -43,17 +42,17 @@ func (b *Backtracking) Init(f, g float64, step float64) Operation {
43
42
panic ("backtracking: initial derivative is non-negative" )
44
43
}
45
44
46
- if b .Decrease == 0 {
47
- b .Decrease = defaultBacktrackingDecrease
45
+ if b .ContractionFactor == 0 {
46
+ b .ContractionFactor = defaultBacktrackingContraction
48
47
}
49
- if b .FuncConst == 0 {
50
- b .FuncConst = defaultBacktrackingFuncConst
48
+ if b .DecreaseFactor == 0 {
49
+ b .DecreaseFactor = defaultBacktrackingDecrease
51
50
}
52
- if b .Decrease <= 0 || b .Decrease >= 1 {
53
- panic ("backtracking: Decrease must be between 0 and 1" )
51
+ if b .ContractionFactor <= 0 || b .ContractionFactor >= 1 {
52
+ panic ("backtracking: ContractionFactor must be between 0 and 1" )
54
53
}
55
- if b .FuncConst <= 0 || b .FuncConst >= 1 {
56
- panic ("backtracking: FuncConst must be between 0 and 1" )
54
+ if b .DecreaseFactor <= 0 || b .DecreaseFactor >= 1 {
55
+ panic ("backtracking: DecreaseFactor must be between 0 and 1" )
57
56
}
58
57
59
58
b .stepSize = step
@@ -69,11 +68,11 @@ func (b *Backtracking) Iterate(f, _ float64) (Operation, float64, error) {
69
68
panic ("backtracking: Init has not been called" )
70
69
}
71
70
72
- if ArmijoConditionMet (f , b .initF , b .initG , b .stepSize , b .FuncConst ) {
71
+ if ArmijoConditionMet (f , b .initF , b .initG , b .stepSize , b .DecreaseFactor ) {
73
72
b .lastOp = MajorIteration
74
73
return b .lastOp , b .stepSize , nil
75
74
}
76
- b .stepSize *= b .Decrease
75
+ b .stepSize *= b .ContractionFactor
77
76
if b .stepSize < minimumBacktrackingStepSize {
78
77
b .lastOp = NoOperation
79
78
return b .lastOp , b .stepSize , ErrLinesearcherFailure
0 commit comments