L-BFGS-B  3.0
Large-scale Bound-constrained Optimization
subsm.f
Go to the documentation of this file.
1 c> \file subsm.f
2 
3 c> \brief Performs the subspace minimization.
4 c>
5 c> Given xcp, l, u, r, an index set that specifies
6 c> the active set at xcp, and an l-BFGS matrix B
7 c> (in terms of WY, WS, SY, WT, head, col, and theta),
8 c> this subroutine computes an approximate solution
9 c> of the subspace problem
10 c>
11 c> (P) min Q(x) = r'(x-xcp) + 1/2 (x-xcp)' B (x-xcp)
12 c>
13 c> subject to l<=x<=u
14 c> x_i=xcp_i for all i in A(xcp)
15 c>
16 c> along the subspace unconstrained Newton direction
17 c>
18 c> d = -(Z'BZ)^(-1) r.
19 c>
20 c> The formula for the Newton direction, given the L-BFGS matrix
21 c> and the Sherman-Morrison formula, is
22 c>
23 c> d = (1/theta)r + (1/theta*2) Z'WK^(-1)W'Z r.
24 c>
25 c> where
26 c> K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
27 c> [L_a -R_z theta*S'AA'S ]
28 c>
29 c> Note that this procedure for computing d differs
30 c> from that described in [1]. One can show that the matrix K is
31 c> equal to the matrix M^[-1]N in that paper.
32 c>
33 c> @param n On entry n is the dimension of the problem.<br/>
34 c> On exit n is unchanged.
35 c>
36 c> @param m On entry m is the maximum number of variable metric corrections
37 c> used to define the limited memory matrix.<br/>
38 c> On exit m is unchanged.
39 c>
40 c> @param nsub On entry nsub is the number of free variables.<br/>
41 c> On exit nsub is unchanged.
42 c>
43 c> @param ind On entry ind specifies the coordinate indices of free variables.<br/>
44 c> On exit ind is unchanged.
45 c>
46 c> @param l On entry l is the lower bound of x.<br/>
47 c> On exit l is unchanged.
48 c>
49 c> @param u On entry u is the upper bound of x.<br/>
50 c> On exit u is unchanged.
51 c>
52 c> @param nbd On entry nbd represents the type of bounds imposed on the
53 c> variables, and must be specified as follows:
54 c> nbd(i)=<ul><li>0 if x(i) is unbounded,</li>
55 c> <li>1 if x(i) has only a lower bound,</li>
56 c> <li>2 if x(i) has both lower and upper bounds, and</li>
57 c> <li>3 if x(i) has only an upper bound.</li></ul>
58 c> On exit nbd is unchanged.
59 c>
60 c> @param x On entry x specifies the Cauchy point xcp.<br/>
61 c> On exit x(i) is the minimizer of Q over the subspace of
62 c> free variables.
63 c>
64 c> @param d On entry d is the reduced gradient of Q at xcp.<br/>
65 c> On exit d is the Newton direction of Q.
66 c>
67 c> @param xp used to safeguard the projected Newton direction<br/>
68 c>
69 c> @param xx On entry it holds the current iterate.<br/>
70 c> On output it is unchanged.
71 c>
72 c> @param gg On entry it holds the gradient at the current iterate.<br/>
73 c> On output it is unchanged.
74 c>
75 c> @param ws On entry this stores S, a set of s-vectors, that defines the
76 c> limited memory BFGS matrix.<br/>
77 c> On exit this array is unchanged.
78 c>
79 c> @param wy On entry this stores Y, a set of y-vectors, that defines the
80 c> limited memory BFGS matrix.<br/>
81 c> On exit this array is unchanged.
82 c>
83 c> @param theta On entry theta is the scaling factor specifying B_0 = theta I.<br/>
84 c> On exit theta is unchanged.
85 c>
86 c> @param col On entry col is the actual number of variable metric
87 c> corrections stored so far.<br/>
88 c> On exit col is unchanged.
89 c>
90 c> @param head On entry head is the location of the first s-vector (or y-vector)
91 c> in S (or Y).<br/>
92 c> On exit col is unchanged.
93 c>
94 c> @param iword On entry iword is unspecified.<br/>
95 c> On exit iword specifies the status of the subspace solution.
96 c> iword = <ul><li>0 if the solution is in the box,</li>
97 c> <li>1 if some bound is encountered.</li></ul>
98 c>
99 c> @param wv working array
100 c>
101 c> @param wn On entry the upper triangle of wn stores the LEL^T factorization
102 c> of the indefinite matrix<br/>
103 c> K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
104 c> [L_a -R_z theta*S'AA'S ]<br/>
105 c> where E = [-I 0]
106 c> [ 0 I]<br/>
107 c> On exit wn is unchanged.
108 c>
109 c> @param iprint must be set by the user;
110 c> It controls the frequency and type of output generated:<ul>
111 c> <li>iprint<0 no output is generated;</li>
112 c> <li>iprint=0 print only one line at the last iteration;</li>
113 c> <li>0<iprint<99 print also f and |proj g| every iprint iterations;</li>
114 c> <li>iprint=99 print details of every iteration except n-vectors;</li>
115 c> <li>iprint=100 print also the changes of active set and final x;</li>
116 c> <li>iprint>100 print details of every iteration including x and g;</li></ul>
117 c> When iprint > 0, the file iterate.dat will be created to
118 c> summarize the iteration.
119 c>
120 c> @param info On entry info is unspecified.<br/>
121 c> On exit info =<ul><li>0 for normal return,</li>
122 c> <li>nonzero for abnormal return
123 c> when the matrix K is ill-conditioned.</li></ul>
124  subroutine subsm ( n, m, nsub, ind, l, u, nbd, x, d, xp, ws, wy,
125  + theta, xx, gg,
126  + col, head, iword, wv, wn, iprint, info )
127  implicit none
128  integer n, m, nsub, col, head, iword, iprint, info,
129  + ind(nsub), nbd(n)
130  double precision theta,
131  + l(n), u(n), x(n), d(n), xp(n), xx(n), gg(n),
132  + ws(n, m), wy(n, m),
133  + wv(2*m), wn(2*m, 2*m)
134 
135 c **********************************************************************
136 c
137 c This routine contains the major changes in the updated version.
138 c The changes are described in the accompanying paper
139 c
140 c Jose Luis Morales, Jorge Nocedal
141 c "Remark On Algorithm 788: L-BFGS-B: Fortran Subroutines for Large-Scale
142 c Bound Constrained Optimization". Decemmber 27, 2010.
143 c
144 c J.L. Morales Departamento de Matematicas,
145 c Instituto Tecnologico Autonomo de Mexico
146 c Mexico D.F.
147 c
148 c J, Nocedal Department of Electrical Engineering and
149 c Computer Science.
150 c Northwestern University. Evanston, IL. USA
151 c
152 c January 17, 2011
153 c
154 c **********************************************************************
155 c
156 c References:
157 c
158 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
159 c memory algorithm for bound constrained optimization'',
160 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
161 c
162 c * * *
163 c
164 c NEOS, November 1994. (Latest revision June 1996.)
165 c Optimization Technology Center.
166 c Argonne National Laboratory and Northwestern University.
167 c Written by
168 c Ciyou Zhu
169 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
170 c
171 c
172 c ************
173 
174  integer pointr,m2,col2,ibd,jy,js,i,j,k
175  double precision alpha, xk, dk, temp1, temp2
176  double precision one,zero
177  parameter(one=1.0d0,zero=0.0d0)
178 c
179  double precision dd_p
180 
181  if (nsub .le. 0) return
182  if (iprint .ge. 99) write (6,1001)
183 
184 c Compute wv = W'Zd.
185 
186  pointr = head
187  do 20 i = 1, col
188  temp1 = zero
189  temp2 = zero
190  do 10 j = 1, nsub
191  k = ind(j)
192  temp1 = temp1 + wy(k,pointr)*d(j)
193  temp2 = temp2 + ws(k,pointr)*d(j)
194  10 continue
195  wv(i) = temp1
196  wv(col + i) = theta*temp2
197  pointr = mod(pointr,m) + 1
198  20 continue
199 
200 c Compute wv:=K^(-1)wv.
201 
202  m2 = 2*m
203  col2 = 2*col
204 
205  !call dtrsl(wn,m2,col2,wv,11,info)
206  !if (info .ne. 0) return
207  call dtrsm('l','u','t','n',col2,1,one,wn,m2,wv,col2)
208  info = 0
209 
210  do 25 i = 1, col
211  wv(i) = -wv(i)
212  25 continue
213 
214  !call dtrsl(wn,m2,col2,wv,01,info)
215  !if (info .ne. 0) return
216  call dtrsm('l','u','n','n',col2,1,one,wn,m2,wv,col2)
217  info = 0
218 
219 c Compute d = (1/theta)d + (1/theta**2)Z'W wv.
220 
221  pointr = head
222  do 40 jy = 1, col
223  js = col + jy
224  do 30 i = 1, nsub
225  k = ind(i)
226  d(i) = d(i) + wy(k,pointr)*wv(jy)/theta
227  + + ws(k,pointr)*wv(js)
228  30 continue
229  pointr = mod(pointr,m) + 1
230  40 continue
231 
232  call dscal( nsub, one/theta, d, 1 )
233 c
234 c-----------------------------------------------------------------
235 c Let us try the projection, d is the Newton direction
236 
237  iword = 0
238 
239  call dcopy ( n, x, 1, xp, 1 )
240 c
241  do 50 i=1, nsub
242  k = ind(i)
243  dk = d(i)
244  xk = x(k)
245  if ( nbd(k) .ne. 0 ) then
246 c
247  if ( nbd(k).eq.1 ) then ! lower bounds only
248  x(k) = max( l(k), xk + dk )
249  if ( x(k).eq.l(k) ) iword = 1
250  else
251 c
252  if ( nbd(k).eq.2 ) then ! upper and lower bounds
253  xk = max( l(k), xk + dk )
254  x(k) = min( u(k), xk )
255  if ( x(k).eq.l(k) .or. x(k).eq.u(k) ) iword = 1
256  else
257 c
258  if ( nbd(k).eq.3 ) then ! upper bounds only
259  x(k) = min( u(k), xk + dk )
260  if ( x(k).eq.u(k) ) iword = 1
261  end if
262  end if
263  end if
264 c
265  else ! free variables
266  x(k) = xk + dk
267  end if
268  50 continue
269 c
270  if ( iword.eq.0 ) then
271  go to 911
272  end if
273 c
274 c check sign of the directional derivative
275 c
276  dd_p = zero
277  do 55 i=1, n
278  dd_p = dd_p + (x(i) - xx(i))*gg(i)
279  55 continue
280  if ( dd_p .gt.zero ) then
281  call dcopy( n, xp, 1, x, 1 )
282  write(6,*) ' Positive dir derivative in projection '
283  write(6,*) ' Using the backtracking step '
284  else
285  go to 911
286  endif
287 c
288 c-----------------------------------------------------------------
289 c
290  alpha = one
291  temp1 = alpha
292  ibd = 0
293  do 60 i = 1, nsub
294  k = ind(i)
295  dk = d(i)
296  if (nbd(k) .ne. 0) then
297  if (dk .lt. zero .and. nbd(k) .le. 2) then
298  temp2 = l(k) - x(k)
299  if (temp2 .ge. zero) then
300  temp1 = zero
301  else if (dk*alpha .lt. temp2) then
302  temp1 = temp2/dk
303  endif
304  else if (dk .gt. zero .and. nbd(k) .ge. 2) then
305  temp2 = u(k) - x(k)
306  if (temp2 .le. zero) then
307  temp1 = zero
308  else if (dk*alpha .gt. temp2) then
309  temp1 = temp2/dk
310  endif
311  endif
312  if (temp1 .lt. alpha) then
313  alpha = temp1
314  ibd = i
315  endif
316  endif
317  60 continue
318 
319  if (alpha .lt. one) then
320  dk = d(ibd)
321  k = ind(ibd)
322  if (dk .gt. zero) then
323  x(k) = u(k)
324  d(ibd) = zero
325  else if (dk .lt. zero) then
326  x(k) = l(k)
327  d(ibd) = zero
328  endif
329  endif
330  do 70 i = 1, nsub
331  k = ind(i)
332  x(k) = x(k) + alpha*d(i)
333  70 continue
334 cccccc
335  911 continue
336 
337  if (iprint .ge. 99) write (6,1004)
338 
339  1001 format (/,'----------------SUBSM entered-----------------',/)
340  1004 format (/,'----------------exit SUBSM --------------------',/)
341 
342  return
343 
344  end
subroutine subsm(n, m, nsub, ind, l, u, nbd, x, d, xp, ws, wy, theta, xx, gg, col, head, iword, wv, wn, iprint, info)
Performs the subspace minimization.
Definition: subsm.f:127