L-BFGS-B  3.0
Large-scale Bound-constrained Optimization
dcsrch.f
Go to the documentation of this file.
1 c> \file dcsrch.f
2 
3 c> \brief This subroutine finds a step that satisfies a sufficient
4 c> decrease condition and a curvature condition.
5 c>
6 c> This subroutine finds a step that satisfies a sufficient
7 c> decrease condition and a curvature condition.
8 c>
9 c> Each call of the subroutine updates an interval with
10 c> endpoints stx and sty. The interval is initially chosen
11 c> so that it contains a minimizer of the modified function
12 c>
13 c> psi(stp) = f(stp) - f(0) - ftol*stp*f'(0).
14 c>
15 c> If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
16 c> interval is chosen so that it contains a minimizer of f.
17 c>
18 c> The algorithm is designed to find a step that satisfies
19 c> the sufficient decrease condition
20 c>
21 c> f(stp) <= f(0) + ftol*stp*f'(0),
22 c>
23 c> and the curvature condition
24 c>
25 c> abs(f'(stp)) <= gtol*abs(f'(0)).
26 c>
27 c> If ftol is less than gtol and if, for example, the function
28 c> is bounded below, then there is always a step which satisfies
29 c> both conditions.
30 c>
31 c> If no step can be found that satisfies both conditions, then
32 c> the algorithm stops with a warning. In this case stp only
33 c> satisfies the sufficient decrease condition.
34 c>
35 c> A typical invocation of dcsrch has the following outline:
36 c>
37 c> ```Fortran
38 c> task = 'START'
39 c> 10 continue
40 c> call dcsrch( ... )
41 c> if (task .eq. 'FG') then
42 c> Evaluate the function and the gradient at stp
43 c> goto 10
44 c> end if
45 c> ```
46 c>
47 c> NOTE: The user must no alter work arrays between calls.
48 c>
49 c> @param f On initial entry f is the value of the function at 0.<br/>
50 c> On subsequent entries f is the value of the
51 c> function at stp.<br/>
52 c> On exit f is the value of the function at stp.
53 c> @param g On initial entry g is the derivative of the function at 0.<br/>
54 c> On subsequent entries g is the derivative of the
55 c> function at stp.<br/>
56 c> On exit g is the derivative of the function at stp.
57 c> @param stp On entry stp is the current estimate of a satisfactory
58 c> step. On initial entry, a positive initial estimate
59 c> must be provided.<br/>
60 c> On exit stp is the current estimate of a satisfactory step
61 c> if task = 'FG'. If task = 'CONV' then stp satisfies
62 c> the sufficient decrease and curvature condition.
63 c> @param ftol On entry ftol specifies a nonnegative tolerance for the
64 c> sufficient decrease condition.<br/>
65 c> On exit ftol is unchanged.
66 c> @param gtol On entry gtol specifies a nonnegative tolerance for the
67 c> curvature condition.<br/>
68 c> On exit gtol is unchanged.
69 c> @param xtol On entry xtol specifies a nonnegative relative tolerance
70 c> for an acceptable step. The subroutine exits with a
71 c> warning if the relative difference between sty and stx
72 c> is less than xtol.<br/>
73 c> On exit xtol is unchanged.
74 c> @param stpmin On entry stpmin is a nonnegative lower bound for the step.<br/>
75 c> On exit stpmin is unchanged.
76 c> @param stpmax On entry stpmax is a nonnegative upper bound for the step.<br/>
77 c> On exit stpmax is unchanged.
78 c> @param task On initial entry task must be set to 'START'.<br/>
79 c> On exit task indicates the required action:
80 c> <ul>
81 c> <li>If task(1:2) = 'FG' then evaluate the function and
82 c> derivative at stp and call dcsrch again.</li>
83 c> <li>If task(1:4) = 'CONV' then the search is successful.</li>
84 c> <li>If task(1:4) = 'WARN' then the subroutine is not able
85 c> to satisfy the convergence conditions. The exit value of
86 c> stp contains the best point found during the search.</li>
87 c> <li>If task(1:5) = 'ERROR' then there is an error in the
88 c> input arguments.</li>
89 c> </ul>
90 c> On exit with convergence, a warning or an error, the
91 c> variable task contains additional information.
92 c> @param isave work array
93 c> @param dsave work array
94  subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
95  + task,isave,dsave)
96  character*(*) task
97  integer isave(2)
98  double precision f,g,stp,ftol,gtol,xtol,stpmin,stpmax
99  double precision dsave(13)
100 c
101 c MINPACK-1 Project. June 1983.
102 c Argonne National Laboratory.
103 c Jorge J. More' and David J. Thuente.
104 c
105 c MINPACK-2 Project. October 1993.
106 c Argonne National Laboratory and University of Minnesota.
107 c Brett M. Averick, Richard G. Carter, and Jorge J. More'.
108 c
109 c **********
110  double precision zero,p5,p66
111  parameter(zero=0.0d0,p5=0.5d0,p66=0.66d0)
112  double precision xtrapl,xtrapu
113  parameter(xtrapl=1.1d0,xtrapu=4.0d0)
114 
115  logical brackt
116  integer stage
117  double precision finit,ftest,fm,fx,fxm,fy,fym,ginit,gtest,
118  + gm,gx,gxm,gy,gym,stx,sty,stmin,stmax,width,width1
119 
120 c Initialization block.
121 
122  if (task(1:5) .eq. 'START') then
123 
124 c Check the input arguments for errors.
125 
126  if (stp .lt. stpmin) task = .LT.'ERROR: STP STPMIN'
127  if (stp .gt. stpmax) task = .GT.'ERROR: STP STPMAX'
128  if (g .ge. zero) task = .GE.'ERROR: INITIAL G ZERO'
129  if (ftol .lt. zero) task = .LT.'ERROR: FTOL ZERO'
130  if (gtol .lt. zero) task = .LT.'ERROR: GTOL ZERO'
131  if (xtol .lt. zero) task = .LT.'ERROR: XTOL ZERO'
132  if (stpmin .lt. zero) task = .LT.'ERROR: STPMIN ZERO'
133  if (stpmax .lt. stpmin) task = .LT.'ERROR: STPMAX STPMIN'
134 
135 c Exit if there are errors on input.
136 
137  if (task(1:5) .eq. 'ERROR') return
138 
139 c Initialize local variables.
140 
141  brackt = .false.
142  stage = 1
143  finit = f
144  ginit = g
145  gtest = ftol*ginit
146  width = stpmax - stpmin
147  width1 = width/p5
148 
149 c The variables stx, fx, gx contain the values of the step,
150 c function, and derivative at the best step.
151 c The variables sty, fy, gy contain the value of the step,
152 c function, and derivative at sty.
153 c The variables stp, f, g contain the values of the step,
154 c function, and derivative at stp.
155 
156  stx = zero
157  fx = finit
158  gx = ginit
159  sty = zero
160  fy = finit
161  gy = ginit
162  stmin = zero
163  stmax = stp + xtrapu*stp
164  task = 'FG'
165 
166  goto 1000
167 
168  else
169 
170 c Restore local variables.
171 
172  if (isave(1) .eq. 1) then
173  brackt = .true.
174  else
175  brackt = .false.
176  endif
177  stage = isave(2)
178  ginit = dsave(1)
179  gtest = dsave(2)
180  gx = dsave(3)
181  gy = dsave(4)
182  finit = dsave(5)
183  fx = dsave(6)
184  fy = dsave(7)
185  stx = dsave(8)
186  sty = dsave(9)
187  stmin = dsave(10)
188  stmax = dsave(11)
189  width = dsave(12)
190  width1 = dsave(13)
191 
192  endif
193 
194 c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
195 c algorithm enters the second stage.
196 
197  ftest = finit + stp*gtest
198  if (stage .eq. 1 .and. f .le. ftest .and. g .ge. zero)
199  + stage = 2
200 
201 c Test for warnings.
202 
203  if (brackt .and. (stp .le. stmin .or. stp .ge. stmax))
204  + task = 'WARNING: ROUNDING ERRORS PREVENT PROGRESS'
205  if (brackt .and. stmax - stmin .le. xtol*stmax)
206  + task = 'WARNING: XTOL TEST SATISFIED'
207  if (stp .eq. stpmax .and. f .le. ftest .and. g .le. gtest)
208  + task = 'WARNING: STP = STPMAX'
209  if (stp .eq. stpmin .and. (f .gt. ftest .or. g .ge. gtest))
210  + task = 'WARNING: STP = STPMIN'
211 
212 c Test for convergence.
213 
214  if (f .le. ftest .and. abs(g) .le. gtol*(-ginit))
215  + task = 'CONVERGENCE'
216 
217 c Test for termination.
218 
219  if (task(1:4) .eq. 'WARN' .or. task(1:4) .eq. 'CONV') goto 1000
220 
221 c A modified function is used to predict the step during the
222 c first stage if a lower function value has been obtained but
223 c the decrease is not sufficient.
224 
225  if (stage .eq. 1 .and. f .le. fx .and. f .gt. ftest) then
226 
227 c Define the modified function and derivative values.
228 
229  fm = f - stp*gtest
230  fxm = fx - stx*gtest
231  fym = fy - sty*gtest
232  gm = g - gtest
233  gxm = gx - gtest
234  gym = gy - gtest
235 
236 c Call dcstep to update stx, sty, and to compute the new step.
237 
238  call dcstep(stx,fxm,gxm,sty,fym,gym,stp,fm,gm,
239  + brackt,stmin,stmax)
240 
241 c Reset the function and derivative values for f.
242 
243  fx = fxm + stx*gtest
244  fy = fym + sty*gtest
245  gx = gxm + gtest
246  gy = gym + gtest
247 
248  else
249 
250 c Call dcstep to update stx, sty, and to compute the new step.
251 
252  call dcstep(stx,fx,gx,sty,fy,gy,stp,f,g,
253  + brackt,stmin,stmax)
254 
255  endif
256 
257 c Decide if a bisection step is needed.
258 
259  if (brackt) then
260  if (abs(sty-stx) .ge. p66*width1) stp = stx + p5*(sty - stx)
261  width1 = width
262  width = abs(sty-stx)
263  endif
264 
265 c Set the minimum and maximum steps allowed for stp.
266 
267  if (brackt) then
268  stmin = min(stx,sty)
269  stmax = max(stx,sty)
270  else
271  stmin = stp + xtrapl*(stp - stx)
272  stmax = stp + xtrapu*(stp - stx)
273  endif
274 
275 c Force the step to be within the bounds stpmax and stpmin.
276 
277  stp = max(stp,stpmin)
278  stp = min(stp,stpmax)
279 
280 c If further progress is not possible, let stp be the best
281 c point obtained during the search.
282 
283  if (brackt .and. (stp .le. stmin .or. stp .ge. stmax)
284  + .or. (brackt .and. stmax-stmin .le. xtol*stmax)) stp = stx
285 
286 c Obtain another function and derivative.
287 
288  task = 'FG'
289 
290  1000 continue
291 
292 c Save local variables.
293 
294  if (brackt) then
295  isave(1) = 1
296  else
297  isave(1) = 0
298  endif
299  isave(2) = stage
300  dsave(1) = ginit
301  dsave(2) = gtest
302  dsave(3) = gx
303  dsave(4) = gy
304  dsave(5) = finit
305  dsave(6) = fx
306  dsave(7) = fy
307  dsave(8) = stx
308  dsave(9) = sty
309  dsave(10) = stmin
310  dsave(11) = stmax
311  dsave(12) = width
312  dsave(13) = width1
313 
314  return
315  end
subroutine dcsrch(f, g, stp, ftol, gtol, xtol, stpmin, stpmax, task, isave, dsave)
This subroutine finds a step that satisfies a sufficient decrease condition and a curvature condition...
Definition: dcsrch.f:96
subroutine dcstep(stx, fx, dx, sty, fy, dy, stp, fp, dp, brackt, stpmin, stpmax)
This subroutine computes a safeguarded step for a search procedure and updates an interval that conta...
Definition: dcstep.f:68