L-BFGS-B  3.0
Large-scale Bound-constrained Optimization
dcstep.f
Go to the documentation of this file.
1 c> \file dcstep.f
2 
3 c> \brief This subroutine computes a safeguarded step for a search
4 c> procedure and updates an interval that contains a step that
5 c> satisfies a sufficient decrease and a curvature condition.
6 c>
7 c> This subroutine computes a safeguarded step for a search
8 c> procedure and updates an interval that contains a step that
9 c> satisfies a sufficient decrease and a curvature condition.
10 c>
11 c> The parameter stx contains the step with the least function
12 c> value. If brackt is set to .true. then a minimizer has
13 c> been bracketed in an interval with endpoints stx and sty.
14 c> The parameter stp contains the current step.
15 c> The subroutine assumes that if brackt is set to .true. then
16 c>
17 c> min(stx,sty) < stp < max(stx,sty),
18 c>
19 c> and that the derivative at stx is negative in the direction
20 c> of the step.
21 c>
22 c> @param stx On entry stx is the best step obtained so far and is an
23 c> endpoint of the interval that contains the minimizer.<br/>
24 c> On exit stx is the updated best step.
25 c>
26 c> @param fx On entry fx is the function at stx.<br/>
27 c> On exit fx is the function at stx.
28 c>
29 c> @param dx On entry dx is the derivative of the function at
30 c> stx. The derivative must be negative in the direction of
31 c> the step, that is, dx and stp - stx must have opposite
32 c> signs.<br/>
33 c> On exit dx is the derivative of the function at stx.
34 c>
35 c> @param sty On entry sty is the second endpoint of the interval that
36 c> contains the minimizer.<br/>
37 c> On exit sty is the updated endpoint of the interval that
38 c> contains the minimizer.
39 c>
40 c> @param fy On entry fy is the function at sty.<br/>
41 c> On exit fy is the function at sty.
42 c>
43 c> @param dy On entry dy is the derivative of the function at sty.<br/>
44 c> On exit dy is the derivative of the function at the exit sty.
45 c>
46 c> @param stp On entry stp is the current step. If brackt is set to .true.
47 c> then on input stp must be between stx and sty.<br/>
48 c> On exit stp is a new trial step.
49 c>
50 c> @param fp On entry fp is the function at stp.<br/>
51 c> On exit fp is unchanged.
52 c>
53 c> @param dp On entry dp is the the derivative of the function at stp.<br/>
54 c> On exit dp is unchanged.
55 c>
56 c> @param brackt On entry brackt specifies if a minimizer has been bracketed.
57 c> Initially brackt must be set to .false.<br/>
58 c> On exit brackt specifies if a minimizer has been bracketed.
59 c> When a minimizer is bracketed brackt is set to .true.
60 c>
61 c> @param stpmin On entry stpmin is a lower bound for the step.<br/>
62 c> On exit stpmin is unchanged.
63 c>
64 c> @param stpmax On entry stpmax is an upper bound for the step.<br/>
65 c> On exit stpmax is unchanged.
66  subroutine dcstep(stx,fx,dx,sty,fy,dy,stp,fp,dp,brackt,
67  + stpmin,stpmax)
68  logical brackt
69  double precision stx,fx,dx,sty,fy,dy,stp,fp,dp,stpmin,stpmax
70 c
71 c MINPACK-1 Project. June 1983
72 c Argonne National Laboratory.
73 c Jorge J. More' and David J. Thuente.
74 c
75 c MINPACK-2 Project. October 1993.
76 c Argonne National Laboratory and University of Minnesota.
77 c Brett M. Averick and Jorge J. More'.
78 c
79 c **********
80  double precision zero,p66,two,three
81  parameter(zero=0.0d0,p66=0.66d0,two=2.0d0,three=3.0d0)
82 
83  double precision gamma,p,q,r,s,sgnd,stpc,stpf,stpq,theta
84 
85  sgnd = dp*(dx/abs(dx))
86 
87 c First case: A higher function value. The minimum is bracketed.
88 c If the cubic step is closer to stx than the quadratic step, the
89 c cubic step is taken, otherwise the average of the cubic and
90 c quadratic steps is taken.
91 
92  if (fp .gt. fx) then
93  theta = three*(fx - fp)/(stp - stx) + dx + dp
94  s = max(abs(theta),abs(dx),abs(dp))
95  gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
96  if (stp .lt. stx) gamma = -gamma
97  p = (gamma - dx) + theta
98  q = ((gamma - dx) + gamma) + dp
99  r = p/q
100  stpc = stx + r*(stp - stx)
101  stpq = stx + ((dx/((fx - fp)/(stp - stx) + dx))/two)*
102  + (stp - stx)
103  if (abs(stpc-stx) .lt. abs(stpq-stx)) then
104  stpf = stpc
105  else
106  stpf = stpc + (stpq - stpc)/two
107  endif
108  brackt = .true.
109 
110 c Second case: A lower function value and derivatives of opposite
111 c sign. The minimum is bracketed. If the cubic step is farther from
112 c stp than the secant step, the cubic step is taken, otherwise the
113 c secant step is taken.
114 
115  else if (sgnd .lt. zero) then
116  theta = three*(fx - fp)/(stp - stx) + dx + dp
117  s = max(abs(theta),abs(dx),abs(dp))
118  gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
119  if (stp .gt. stx) gamma = -gamma
120  p = (gamma - dp) + theta
121  q = ((gamma - dp) + gamma) + dx
122  r = p/q
123  stpc = stp + r*(stx - stp)
124  stpq = stp + (dp/(dp - dx))*(stx - stp)
125  if (abs(stpc-stp) .gt. abs(stpq-stp)) then
126  stpf = stpc
127  else
128  stpf = stpq
129  endif
130  brackt = .true.
131 
132 c Third case: A lower function value, derivatives of the same sign,
133 c and the magnitude of the derivative decreases.
134 
135  else if (abs(dp) .lt. abs(dx)) then
136 
137 c The cubic step is computed only if the cubic tends to infinity
138 c in the direction of the step or if the minimum of the cubic
139 c is beyond stp. Otherwise the cubic step is defined to be the
140 c secant step.
141 
142  theta = three*(fx - fp)/(stp - stx) + dx + dp
143  s = max(abs(theta),abs(dx),abs(dp))
144 
145 c The case gamma = 0 only arises if the cubic does not tend
146 c to infinity in the direction of the step.
147 
148  gamma = s*sqrt(max(zero,(theta/s)**2-(dx/s)*(dp/s)))
149  if (stp .gt. stx) gamma = -gamma
150  p = (gamma - dp) + theta
151  q = (gamma + (dx - dp)) + gamma
152  r = p/q
153  if (r .lt. zero .and. gamma .ne. zero) then
154  stpc = stp + r*(stx - stp)
155  else if (stp .gt. stx) then
156  stpc = stpmax
157  else
158  stpc = stpmin
159  endif
160  stpq = stp + (dp/(dp - dx))*(stx - stp)
161 
162  if (brackt) then
163 
164 c A minimizer has been bracketed. If the cubic step is
165 c closer to stp than the secant step, the cubic step is
166 c taken, otherwise the secant step is taken.
167 
168  if (abs(stpc-stp) .lt. abs(stpq-stp)) then
169  stpf = stpc
170  else
171  stpf = stpq
172  endif
173  if (stp .gt. stx) then
174  stpf = min(stp+p66*(sty-stp),stpf)
175  else
176  stpf = max(stp+p66*(sty-stp),stpf)
177  endif
178  else
179 
180 c A minimizer has not been bracketed. If the cubic step is
181 c farther from stp than the secant step, the cubic step is
182 c taken, otherwise the secant step is taken.
183 
184  if (abs(stpc-stp) .gt. abs(stpq-stp)) then
185  stpf = stpc
186  else
187  stpf = stpq
188  endif
189  stpf = min(stpmax,stpf)
190  stpf = max(stpmin,stpf)
191  endif
192 
193 c Fourth case: A lower function value, derivatives of the same sign,
194 c and the magnitude of the derivative does not decrease. If the
195 c minimum is not bracketed, the step is either stpmin or stpmax,
196 c otherwise the cubic step is taken.
197 
198  else
199  if (brackt) then
200  theta = three*(fp - fy)/(sty - stp) + dy + dp
201  s = max(abs(theta),abs(dy),abs(dp))
202  gamma = s*sqrt((theta/s)**2 - (dy/s)*(dp/s))
203  if (stp .gt. sty) gamma = -gamma
204  p = (gamma - dp) + theta
205  q = ((gamma - dp) + gamma) + dy
206  r = p/q
207  stpc = stp + r*(sty - stp)
208  stpf = stpc
209  else if (stp .gt. stx) then
210  stpf = stpmax
211  else
212  stpf = stpmin
213  endif
214  endif
215 
216 c Update the interval which contains a minimizer.
217 
218  if (fp .gt. fx) then
219  sty = stp
220  fy = fp
221  dy = dp
222  else
223  if (sgnd .lt. zero) then
224  sty = stx
225  fy = fx
226  dy = dx
227  endif
228  stx = stp
229  fx = fp
230  dx = dp
231  endif
232 
233 c Compute the new step.
234 
235  stp = stpf
236 
237  return
238  end
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