1 C ------------------------------------------------------------------
3 C **************************
4 C LINE SEARCH ROUTINE MCSRCH
5 C **************************
7 SUBROUTINE MCSRCH
(N
,X
,F
,G
,S
,STP
,FTOL
,XTOL
,MAXFEV
,INFO
,NFEV
,WA
)
8 INTEGER N
,MAXFEV
,INFO
,NFEV
9 DOUBLE PRECISION F
,STP
,FTOL
,GTOL
,XTOL
,STPMIN
,STPMAX
10 DOUBLE PRECISION X
(N
),G
(N
),S
(N
),WA
(N
)
11 COMMON /LB3
/MP
,LP
,GTOL
,STPMIN
,STPMAX
16 C A slight modification of the subroutine CSRCH of More' and Thuente.
17 C The changes are to allow reverse communication, and do not affect
18 C the performance of the routine.
20 C THE PURPOSE OF MCSRCH IS TO FIND A STEP WHICH SATISFIES
21 C A SUFFICIENT DECREASE CONDITION AND A CURVATURE CONDITION.
23 C AT EACH STAGE THE SUBROUTINE UPDATES AN INTERVAL OF
24 C UNCERTAINTY WITH ENDPOINTS STX AND STY. THE INTERVAL OF
25 C UNCERTAINTY IS INITIALLY CHOSEN SO THAT IT CONTAINS A
26 C MINIMIZER OF THE MODIFIED FUNCTION
28 C F(X+STP*S) - F(X) - FTOL*STP*(GRADF(X)'S).
30 C IF A STEP IS OBTAINED FOR WHICH THE MODIFIED FUNCTION
31 C HAS A NONPOSITIVE FUNCTION VALUE AND NONNEGATIVE DERIVATIVE,
32 C THEN THE INTERVAL OF UNCERTAINTY IS CHOSEN SO THAT IT
33 C CONTAINS A MINIMIZER OF F(X+STP*S).
35 C THE ALGORITHM IS DESIGNED TO FIND A STEP WHICH SATISFIES
36 C THE SUFFICIENT DECREASE CONDITION
38 C F(X+STP*S) .LE. F(X) + FTOL*STP*(GRADF(X)'S),
40 C AND THE CURVATURE CONDITION
42 C ABS(GRADF(X+STP*S)'S)) .LE. GTOL*ABS(GRADF(X)'S).
44 C IF FTOL IS LESS THAN GTOL AND IF, FOR EXAMPLE, THE FUNCTION
45 C IS BOUNDED BELOW, THEN THERE IS ALWAYS A STEP WHICH SATISFIES
46 C BOTH CONDITIONS. IF NO STEP CAN BE FOUND WHICH SATISFIES BOTH
47 C CONDITIONS, THEN THE ALGORITHM USUALLY STOPS WHEN ROUNDING
48 C ERRORS PREVENT FURTHER PROGRESS. IN THIS CASE STP ONLY
49 C SATISFIES THE SUFFICIENT DECREASE CONDITION.
51 C THE SUBROUTINE STATEMENT IS
53 C SUBROUTINE MCSRCH(N,X,F,G,S,STP,FTOL,XTOL, MAXFEV,INFO,NFEV,WA)
56 C N IS A POSITIVE INTEGER INPUT VARIABLE SET TO THE NUMBER
59 C X IS AN ARRAY OF LENGTH N. ON INPUT IT MUST CONTAIN THE
60 C BASE POINT FOR THE LINE SEARCH. ON OUTPUT IT CONTAINS
63 C F IS A VARIABLE. ON INPUT IT MUST CONTAIN THE VALUE OF F
64 C AT X. ON OUTPUT IT CONTAINS THE VALUE OF F AT X + STP*S.
66 C G IS AN ARRAY OF LENGTH N. ON INPUT IT MUST CONTAIN THE
67 C GRADIENT OF F AT X. ON OUTPUT IT CONTAINS THE GRADIENT
70 C S IS AN INPUT ARRAY OF LENGTH N WHICH SPECIFIES THE
73 C STP IS A NONNEGATIVE VARIABLE. ON INPUT STP CONTAINS AN
74 C INITIAL ESTIMATE OF A SATISFACTORY STEP. ON OUTPUT
75 C STP CONTAINS THE FINAL ESTIMATE.
77 C FTOL AND GTOL ARE NONNEGATIVE INPUT VARIABLES. (In this reverse
78 C communication implementation GTOL is defined in a COMMON
79 C statement.) TERMINATION OCCURS WHEN THE SUFFICIENT DECREASE
80 C CONDITION AND THE DIRECTIONAL DERIVATIVE CONDITION ARE
83 C XTOL IS A NONNEGATIVE INPUT VARIABLE. TERMINATION OCCURS
84 C WHEN THE RELATIVE WIDTH OF THE INTERVAL OF UNCERTAINTY
87 C STPMIN AND STPMAX ARE NONNEGATIVE INPUT VARIABLES WHICH
88 C SPECIFY LOWER AND UPPER BOUNDS FOR THE STEP. (In this reverse
89 C communication implementatin they are defined in a COMMON
92 C MAXFEV IS A POSITIVE INTEGER INPUT VARIABLE. TERMINATION
93 C OCCURS WHEN THE NUMBER OF CALLS TO FCN IS AT LEAST
94 C MAXFEV BY THE END OF AN ITERATION.
96 C INFO IS AN INTEGER OUTPUT VARIABLE SET AS FOLLOWS:
98 C INFO = 0 IMPROPER INPUT PARAMETERS.
100 C INFO =-1 A RETURN IS MADE TO COMPUTE THE FUNCTION AND GRADIENT.
102 C INFO = 1 THE SUFFICIENT DECREASE CONDITION AND THE
103 C DIRECTIONAL DERIVATIVE CONDITION HOLD.
105 C INFO = 2 RELATIVE WIDTH OF THE INTERVAL OF UNCERTAINTY
108 C INFO = 3 NUMBER OF CALLS TO FCN HAS REACHED MAXFEV.
110 C INFO = 4 THE STEP IS AT THE LOWER BOUND STPMIN.
112 C INFO = 5 THE STEP IS AT THE UPPER BOUND STPMAX.
114 C INFO = 6 ROUNDING ERRORS PREVENT FURTHER PROGRESS.
115 C THERE MAY NOT BE A STEP WHICH SATISFIES THE
116 C SUFFICIENT DECREASE AND CURVATURE CONDITIONS.
117 C TOLERANCES MAY BE TOO SMALL.
119 C NFEV IS AN INTEGER OUTPUT VARIABLE SET TO THE NUMBER OF
122 C WA IS A WORK ARRAY OF LENGTH N.
128 C FORTRAN-SUPPLIED...ABS,MAX,MIN
130 C ARGONNE NATIONAL LABORATORY. MINPACK PROJECT. JUNE 1983
131 C JORGE J. MORE', DAVID J. THUENTE
135 LOGICAL BRACKT
,STAGE1
136 DOUBLE PRECISION DG
,DGM
,DGINIT
,DGTEST
,DGX
,DGXM
,DGY
,DGYM
,
137 * FINIT
,FTEST1
,FM
,FX
,FXM
,FY
,FYM
,P5
,P66
,STX
,STY
,
138 * STMIN
,STMAX
,WIDTH
,WIDTH1
,XTRAPF
,ZERO
139 DATA P5
,P66
,XTRAPF
,ZERO
/0.5D0
,0.66D0
,4.0D0
,0.0D0
/
140 IF(INFO
.EQ
.-1) GO TO 45
143 C CHECK THE INPUT PARAMETERS FOR ERRORS.
145 IF (N
.LE
. 0 .OR
. STP
.LE
. ZERO
.OR
. FTOL
.LT
. ZERO
.OR
.
146 * GTOL
.LT
. ZERO
.OR
. XTOL
.LT
. ZERO
.OR
. STPMIN
.LT
. ZERO
147 * .OR
. STPMAX
.LT
. STPMIN
.OR
. MAXFEV
.LE
. 0) RETURN
149 C COMPUTE THE INITIAL GRADIENT IN THE SEARCH DIRECTION
150 C AND CHECK THAT S IS A DESCENT DIRECTION.
154 DGINIT
= DGINIT
+ G
(J
)*S
(J
)
156 IF (DGINIT
.GE
. ZERO
) then
158 15 FORMAT(/' THE SEARCH DIRECTION IS NOT A DESCENT DIRECTION')
162 C INITIALIZE LOCAL VARIABLES.
169 WIDTH
= STPMAX
- STPMIN
175 C THE VARIABLES STX, FX, DGX CONTAIN THE VALUES OF THE STEP,
176 C FUNCTION, AND DIRECTIONAL DERIVATIVE AT THE BEST STEP.
177 C THE VARIABLES STY, FY, DGY CONTAIN THE VALUE OF THE STEP,
178 C FUNCTION, AND DERIVATIVE AT THE OTHER ENDPOINT OF
179 C THE INTERVAL OF UNCERTAINTY.
180 C THE VARIABLES STP, F, DG CONTAIN THE VALUES OF THE STEP,
181 C FUNCTION, AND DERIVATIVE AT THE CURRENT STEP.
190 C START OF ITERATION.
194 C SET THE MINIMUM AND MAXIMUM STEPS TO CORRESPOND
195 C TO THE PRESENT INTERVAL OF UNCERTAINTY.
202 STMAX
= STP
+ XTRAPF*
(STP
- STX
)
205 C FORCE THE STEP TO BE WITHIN THE BOUNDS STPMAX AND STPMIN.
207 STP
= MAX
(STP
,STPMIN
)
208 STP
= MIN
(STP
,STPMAX
)
210 C IF AN UNUSUAL TERMINATION IS TO OCCUR THEN LET
211 C STP BE THE LOWEST POINT OBTAINED SO FAR.
213 IF ((BRACKT
.AND
. (STP
.LE
. STMIN
.OR
. STP
.GE
. STMAX
))
214 * .OR
. NFEV
.GE
. MAXFEV
-1 .OR
. INFOC
.EQ
. 0
215 * .OR
. (BRACKT
.AND
. STMAX
-STMIN
.LE
. XTOL*STMAX
)) STP
= STX
217 C EVALUATE THE FUNCTION AND GRADIENT AT STP
218 C AND COMPUTE THE DIRECTIONAL DERIVATIVE.
219 C We return to main program to obtain F and G.
222 X
(J
) = WA
(J
) + STP*S
(J
)
233 FTEST1
= FINIT
+ STP*DGTEST
235 C TEST FOR CONVERGENCE.
237 IF ((BRACKT
.AND
. (STP
.LE
. STMIN
.OR
. STP
.GE
. STMAX
))
238 * .OR
. INFOC
.EQ
. 0) INFO
= 6
239 IF (STP
.EQ
. STPMAX
.AND
.
240 * F
.LE
. FTEST1
.AND
. DG
.LE
. DGTEST
) INFO
= 5
241 IF (STP
.EQ
. STPMIN
.AND
.
242 * (F
.GT
. FTEST1
.OR
. DG
.GE
. DGTEST
)) INFO
= 4
243 IF (NFEV
.GE
. MAXFEV
) INFO
= 3
244 IF (BRACKT
.AND
. STMAX
-STMIN
.LE
. XTOL*STMAX
) INFO
= 2
245 IF (F
.LE
. FTEST1
.AND
. DABS
(DG
) .LE
. GTOL*
(-DGINIT
)) INFO
= 1
247 C CHECK FOR TERMINATION.
249 IF (INFO
.NE
. 0) RETURN
251 C IN THE FIRST STAGE WE SEEK A STEP FOR WHICH THE MODIFIED
252 C FUNCTION HAS A NONPOSITIVE VALUE AND NONNEGATIVE DERIVATIVE.
254 IF (STAGE1
.AND
. F
.LE
. FTEST1
.AND
.
255 * DG
.GE
. MIN
(FTOL
,GTOL
)*DGINIT
) STAGE1
= .FALSE
.
257 C A MODIFIED FUNCTION IS USED TO PREDICT THE STEP ONLY IF
258 C WE HAVE NOT OBTAINED A STEP FOR WHICH THE MODIFIED
259 C FUNCTION HAS A NONPOSITIVE FUNCTION VALUE AND NONNEGATIVE
260 C DERIVATIVE, AND IF A LOWER FUNCTION VALUE HAS BEEN
261 C OBTAINED BUT THE DECREASE IS NOT SUFFICIENT.
263 IF (STAGE1
.AND
. F
.LE
. FX
.AND
. F
.GT
. FTEST1
) THEN
265 C DEFINE THE MODIFIED FUNCTION AND DERIVATIVE VALUES.
268 FXM
= FX
- STX*DGTEST
269 FYM
= FY
- STY*DGTEST
274 C CALL CSTEP TO UPDATE THE INTERVAL OF UNCERTAINTY
275 C AND TO COMPUTE THE NEW STEP.
277 CALL MCSTEP
(STX
,FXM
,DGXM
,STY
,FYM
,DGYM
,STP
,FM
,DGM
,
278 * BRACKT
,STMIN
,STMAX
,INFOC
)
280 C RESET THE FUNCTION AND GRADIENT VALUES FOR F.
282 FX
= FXM
+ STX*DGTEST
283 FY
= FYM
+ STY*DGTEST
288 C CALL MCSTEP TO UPDATE THE INTERVAL OF UNCERTAINTY
289 C AND TO COMPUTE THE NEW STEP.
291 CALL MCSTEP
(STX
,FX
,DGX
,STY
,FY
,DGY
,STP
,F
,DG
,
292 * BRACKT
,STMIN
,STMAX
,INFOC
)
295 C FORCE A SUFFICIENT DECREASE IN THE SIZE OF THE
296 C INTERVAL OF UNCERTAINTY.
299 IF (DABS
(STY
-STX
) .GE
. P66*WIDTH1
)
300 * STP
= STX
+ P5*
(STY
- STX
)
302 WIDTH
= DABS
(STY
-STX
)
309 C LAST LINE OF SUBROUTINE MCSRCH.