This driver shows how to replace the default stopping test by other termination criteria. It also illustrates how to print the values of several parameters during the course of the iteration. The sample problem used here is the same as in DRIVER1 (the extended Rosenbrock function with bounds on the variables). (Fortran-77 version)
53 use json_writer,
only: json_write_aggregate
63 parameter(nmax=1024, mmax=17)
71 character*60 task, csave
74 + nbd(nmax), iwa(3*nmax), isave(44)
75 double precision f, factr, pgtol,
76 + x(nmax), l(nmax), u(nmax), g(nmax), dsave(29),
77 + wa(2*mmax*nmax+5*nmax+11*mmax*mmax+8*mmax)
81 double precision t1, t2
87 character*512 lbfgsb_json
88 character*64 env_nfg_limit
138 16
format(/,5x,
'Solving sample problem.',
139 + /,5x,
' (f = 0.0 at the optimal solution.)',/)
146 call get_environment_variable(
'LBFGSB_JSON_OUTPUT', lbfgsb_json)
147 json_active = (len_trim(lbfgsb_json) .gt. 0)
149 call get_environment_variable(
'LBFGSB_NFG_LIMIT', env_nfg_limit)
150 if (len_trim(env_nfg_limit) .gt. 0)
then
151 read(env_nfg_limit, *) nfg_limit
160 call setulb(n,m,x,l,u,nbd,f,g,factr,pgtol,wa,iwa,task,iprint,
161 + csave,lsave,isave,dsave)
163 if (task(1:2) .eq.
'FG')
then
169 f=.25d0*(x(1)-1.d0)**2
171 f=f+(x(i)-x(i-1)**2)**2
178 g(1)=2.d0*(x(1)-1.d0)-1.6d1*x(1)*t1
182 g(i)=8.d0*t2-1.6d1*x(i)*t1
190 if (task(1:5) .eq.
'NEW_X')
then
206 if (isave(34) .ge. nfg_limit)
207 + task=
'STOP: TOTAL NO. of f AND g EVALUATIONS EXCEEDS LIMIT'
212 if (dsave(13) .le. 1.d-10*(1.0d0 + abs(f)))
213 + task=
'STOP: THE PROJECTED GRADIENT IS SUFFICIENTLY SMALL'
226 write (6,
'(2(a,i5,4x),a,1p,d12.5,4x,a,1p,d12.5)')
'Iterate'
227 + ,isave(30),
'nfg =',isave(34),
'f =',f,
'|proj g| =',dsave(13)
232 if (task(1:4) .eq.
'STOP')
then
234 write (6,*)
'Final X='
235 write (6,
'((1x,1p, 6(1x,d11.4)))') (x(i),i = 1,n)
247 if (json_active)
then
248 call json_write_aggregate(trim(lbfgsb_json), task, f,
subroutine setulb(n, m, x, l, u, nbd, f, g, factr, pgtol, wa, iwa, task, iprint, csave, lsave, isave, dsave)
This subroutine partitions the working arrays wa and iwa, and then uses the limited memory BFGS metho...