| 1 |
heimbach |
1.1 |
\section{The line search optimisation algorithm |
| 2 |
|
|
\label{sectionoptim}} |
| 3 |
edhill |
1.5 |
\begin{rawhtml} |
| 4 |
|
|
<!-- CMIREDIR:lsearch_optim: --> |
| 5 |
|
|
\end{rawhtml} |
| 6 |
heimbach |
1.1 |
|
| 7 |
heimbach |
1.6 |
Author: Patrick Heimbach |
| 8 |
|
|
|
| 9 |
heimbach |
1.1 |
\subsection{General features} |
| 10 |
|
|
|
| 11 |
|
|
The line search algorithm is based on a quasi-Newton |
| 12 |
|
|
variable storage method which was implemented by |
| 13 |
heimbach |
1.4 |
\cite{gil-lem:89}. |
| 14 |
heimbach |
1.1 |
|
| 15 |
|
|
TO BE CONTINUED... |
| 16 |
|
|
|
| 17 |
|
|
\subsection{The online vs. offline version} |
| 18 |
|
|
|
| 19 |
|
|
\begin{itemize} |
| 20 |
|
|
% |
| 21 |
|
|
\item {\bf Online version} \\ |
| 22 |
|
|
Every call to {\it simul} refers to an execution of the |
| 23 |
|
|
forward and adjoint model. |
| 24 |
|
|
Several iterations of optimization may thus be performed within |
| 25 |
|
|
a single run of the main program (lsopt\_top). |
| 26 |
|
|
The following cases may occur: |
| 27 |
|
|
% |
| 28 |
|
|
\begin{itemize} |
| 29 |
|
|
\item |
| 30 |
|
|
cold start only (no optimization) |
| 31 |
|
|
\item |
| 32 |
|
|
cold start, followed by one or several iterations of optimization |
| 33 |
|
|
\item |
| 34 |
|
|
warm start from previous cold start with one or several iterations |
| 35 |
|
|
\item |
| 36 |
|
|
warm start from previous warm start with one or several iterations |
| 37 |
|
|
\end{itemize} |
| 38 |
|
|
% |
| 39 |
|
|
\item {\bf Offline version} \\ |
| 40 |
|
|
Every call to simul refers to a read procedure which |
| 41 |
|
|
reads the result of a forward and adjoint run |
| 42 |
|
|
Therefore, only one call to simul is allowed, |
| 43 |
|
|
{\tt itmax = 0}, for cold start |
| 44 |
|
|
{\tt itmax = 1}, for warm start |
| 45 |
|
|
Also, at the end, {\bf x(i+1)} needs to be computed and saved |
| 46 |
|
|
to be available for the offline model and adjoint run |
| 47 |
|
|
\end{itemize} |
| 48 |
|
|
|
| 49 |
|
|
In order to achieve minimum difference between the online and offline code |
| 50 |
|
|
{\bf xdiff(i+1)} is stored to file at the end of an (offline) iteration, |
| 51 |
|
|
but recomputed identically at the beginning of the next iteration. |
| 52 |
|
|
|
| 53 |
|
|
\subsection{Number of iterations vs. number of simulations} |
| 54 |
|
|
|
| 55 |
|
|
{\tt - itmax:} controls the max. number of iterations \\ |
| 56 |
|
|
{\tt - nfunc:} controls the max. number of simulations |
| 57 |
|
|
within one iteration |
| 58 |
|
|
|
| 59 |
|
|
\paragraph{Summary} ~ \\ |
| 60 |
|
|
From one iteration to the next the descent direction changes. |
| 61 |
|
|
Within one iteration more than one forward and adjoint |
| 62 |
|
|
run may be performed. |
| 63 |
|
|
The updated control used as input for these simulations uses the same |
| 64 |
|
|
descent direction, but different step sizes. |
| 65 |
|
|
|
| 66 |
|
|
\paragraph{Description} ~ \\ |
| 67 |
|
|
From one iteration to the next the descent direction dd changes using |
| 68 |
|
|
the result for the adjoint vector gg of the previous iteration. |
| 69 |
|
|
In lsline the updated control |
| 70 |
|
|
\[ |
| 71 |
|
|
\tt |
| 72 |
|
|
xdiff(i,1) = xx(i-1) + tact(i-1,1)*dd(i-1) |
| 73 |
|
|
\] |
| 74 |
|
|
serves as input for |
| 75 |
|
|
a forward and adjoint model run yielding a new {\tt gg(i,1)}. |
| 76 |
|
|
In general, the new solution passes the 1st and 2nd Wolfe tests |
| 77 |
|
|
so {\tt xdiff(i,1)} represents the solution sought: |
| 78 |
|
|
\[ |
| 79 |
|
|
{\tt xx(i) = xdiff(i,1)} |
| 80 |
|
|
\] |
| 81 |
|
|
If one of the two tests fails, |
| 82 |
|
|
an inter- or extrapolation is invoked to determine |
| 83 |
|
|
a new step size {\tt tact(i-1,2)}. |
| 84 |
|
|
If more than one function call is permitted, |
| 85 |
|
|
the new step size is used together |
| 86 |
|
|
with the "old" descent direction {\tt dd(i-1)} |
| 87 |
|
|
(i.e. dd is not updated using the new {\tt gg(i)}), |
| 88 |
|
|
to compute a new |
| 89 |
|
|
\[ |
| 90 |
|
|
{\tt xdiff(i,2) = xx(i-1) + tact(i-1,2)*dd(i-1)} |
| 91 |
|
|
\] |
| 92 |
|
|
that serves as input |
| 93 |
|
|
in a new forward and adjoint run, yielding {\tt gg(i,2)}. |
| 94 |
cnh |
1.2 |
If now, both Wolfe tests are successful, |
| 95 |
heimbach |
1.1 |
the updated solution is given by |
| 96 |
|
|
\[ |
| 97 |
|
|
\tt |
| 98 |
|
|
xx(i) = xdiff(i,2) = xx(i-1) + tact(i-1,2)*dd(i-1) |
| 99 |
|
|
\] |
| 100 |
|
|
|
| 101 |
|
|
In order to save memory both the fields dd and xdiff |
| 102 |
|
|
have a double usage. |
| 103 |
|
|
% |
| 104 |
|
|
\begin{itemize} |
| 105 |
|
|
% |
| 106 |
|
|
\item [{\tt xdiff}] ~\\ |
| 107 |
|
|
- in {\it lsopt\_top}: used as {\tt x(i) - x(i-1)} for Hessian update \\ |
| 108 |
|
|
- in {\it lsline}: intermediate result for control update |
| 109 |
|
|
{\tt x = x + tact*dd} |
| 110 |
|
|
% |
| 111 |
|
|
\item [{\tt dd}] ~\\ |
| 112 |
|
|
- in {\it lsopt\_top, lsline}: descent vector, {\tt dd = -gg} |
| 113 |
|
|
and {\tt hessupd} \\ |
| 114 |
|
|
- in {\it dgscale}: intermediate result to compute new preconditioner |
| 115 |
|
|
% |
| 116 |
|
|
\end{itemize} |
| 117 |
|
|
|
| 118 |
|
|
\paragraph{The parameter file lsopt.par} |
| 119 |
|
|
|
| 120 |
|
|
% |
| 121 |
|
|
\begin{itemize} |
| 122 |
|
|
% |
| 123 |
|
|
\item {\bf NUPDATE} |
| 124 |
|
|
max. no. of update pairs {\tt (gg(i)-gg(i-1), xx(i)-xx(i-1))} |
| 125 |
|
|
to be stored in {\tt OPWARMD} to estimate Hessian |
| 126 |
|
|
[pair of current iter. is stored in |
| 127 |
|
|
{\tt (2*jmax+2, 2*jmax+3)} |
| 128 |
|
|
jmax must be > 0 to access these entries] |
| 129 |
|
|
Presently {\tt NUPDATE} must be > 0 |
| 130 |
|
|
(i.e. iteration without reference to previous |
| 131 |
|
|
iterations through {\tt OPWARMD} has not been tested) |
| 132 |
|
|
% |
| 133 |
|
|
\item {\bf EPSX} |
| 134 |
|
|
relative precision on xx bellow which xx should not be improved |
| 135 |
|
|
% |
| 136 |
|
|
\item {\bf EPSG} |
| 137 |
|
|
relative precision on gg below which optimization is |
| 138 |
|
|
considered successful |
| 139 |
|
|
% |
| 140 |
|
|
\item {\bf IPRINT} |
| 141 |
|
|
controls verbose (>=1) or non-verbose output |
| 142 |
|
|
% |
| 143 |
|
|
\item {\bf NUMITER} |
| 144 |
|
|
max. number of iterations of optimisation; |
| 145 |
|
|
NUMTER = 0: cold start only, no optimization |
| 146 |
|
|
% |
| 147 |
|
|
\item {\bf ITER\_NUM} |
| 148 |
|
|
index of new restart file to be created (not necessarily = NUMITER!) |
| 149 |
|
|
% |
| 150 |
|
|
\item {\bf NFUNC} |
| 151 |
|
|
max. no. of simulations per iteration |
| 152 |
|
|
(must be > 0); |
| 153 |
|
|
is used if step size {\tt tact} is inter-/extrapolated; |
| 154 |
|
|
in this case, if NFUNC > 1, a new simulation is performed with |
| 155 |
|
|
same gradient but "improved" step size |
| 156 |
|
|
% |
| 157 |
|
|
\item {\bf FMIN} |
| 158 |
|
|
first guess cost function value |
| 159 |
|
|
(only used as long as first iteration not completed, |
| 160 |
|
|
i.e. for jmax <= 0) |
| 161 |
|
|
% |
| 162 |
|
|
\end{itemize} |
| 163 |
|
|
|
| 164 |
|
|
\paragraph{OPWARMI, OPWARMD files} |
| 165 |
|
|
Two files retain values of previous iterations which are |
| 166 |
|
|
used in latest iteration to update Hessian: |
| 167 |
|
|
\begin{itemize} |
| 168 |
|
|
% |
| 169 |
|
|
\item {\bf OPWARMI}: contains index settings and scalar variables |
| 170 |
|
|
|
| 171 |
|
|
{\footnotesize |
| 172 |
|
|
\begin{tabular}{ll} |
| 173 |
|
|
{\tt n = nn} & no. of control variables \\ |
| 174 |
|
|
{\tt fc = ff} & cost value of last iteration \\ |
| 175 |
|
|
{\tt isize} & no. of bytes per record in OPWARMD \\ |
| 176 |
|
|
{\tt m = nupdate} & max. no. of updates for Hessian \\ |
| 177 |
|
|
{\tt jmin, jmax} & pointer indices for OPWARMD file (cf. below) \\ |
| 178 |
|
|
{\tt gnorm0} & norm of first (cold start) gradient gg \\ |
| 179 |
|
|
{\tt iabsiter} & total number of iterations with respect to cold start |
| 180 |
|
|
\end{tabular} |
| 181 |
|
|
} |
| 182 |
|
|
% |
| 183 |
|
|
\item {\bf OPWARMD}: contains vectors (control and gradient) |
| 184 |
|
|
|
| 185 |
|
|
{\scriptsize |
| 186 |
|
|
\begin{tabular}{cll} |
| 187 |
|
|
entry & name & description \\ |
| 188 |
|
|
\hline |
| 189 |
|
|
1 & {\tt xx(i)} & control vector of latest iteration \\ |
| 190 |
|
|
2 & {\tt gg(i)} & gradient of latest iteration \\ |
| 191 |
|
|
3 & {\tt xdiff(i),diag} & preconditioning vector; (1,...,1) |
| 192 |
|
|
for cold start \\ |
| 193 |
|
|
2*jmax+2 & {\tt gold=g(i)-g(i-1)} & for last update (jmax) \\ |
| 194 |
|
|
2*jmax+3 & {\tt xdiff=tact*d=xx(i)-xx(i-1)} & for last update (jmax) |
| 195 |
|
|
\end{tabular} |
| 196 |
|
|
} |
| 197 |
|
|
% |
| 198 |
|
|
\end{itemize} |
| 199 |
|
|
% |
| 200 |
|
|
\begin{figure}[b!] |
| 201 |
|
|
{\footnotesize |
| 202 |
|
|
\begin{verbatim} |
| 203 |
|
|
|
| 204 |
|
|
Example 1: jmin = 1, jmax = 3, mupd = 5 |
| 205 |
|
|
|
| 206 |
|
|
1 2 3 | 4 5 6 7 8 9 empty empty |
| 207 |
|
|
|___|___|___| | |___|___| |___|___| |___|___| |___|___| |___|___| |
| 208 |
|
|
0 | 1 2 3 |
| 209 |
|
|
|
| 210 |
|
|
Example 2: jmin = 3, jmax = 7, mupd = 5 ---> jmax = 2 |
| 211 |
|
|
|
| 212 |
|
|
1 2 3 | |
| 213 |
|
|
|___|___|___| | |___|___| |___|___| |___|___| |___|___| |___|___| |
| 214 |
|
|
| 6 7 3 4 5 |
| 215 |
|
|
|
| 216 |
|
|
\end{verbatim} |
| 217 |
|
|
} |
| 218 |
|
|
\caption{Examples of OPWARM file handling} |
| 219 |
|
|
\label{fig:opwarm} |
| 220 |
|
|
\end{figure} |
| 221 |
|
|
|
| 222 |
|
|
\paragraph{Error handling} |
| 223 |
|
|
|
| 224 |
|
|
|
| 225 |
|
|
|
| 226 |
|
|
\newpage |
| 227 |
|
|
|
| 228 |
adcroft |
1.3 |
\begin{figure} |
| 229 |
|
|
%\input{part8/lsopt_flow_1} |
| 230 |
|
|
{\scriptsize |
| 231 |
|
|
\begin{verbatim} |
| 232 |
|
|
lsopt_top |
| 233 |
|
|
| |
| 234 |
|
|
|---- check arguments |
| 235 |
|
|
|---- CALL INSTORE |
| 236 |
|
|
| | |
| 237 |
|
|
| |---- determine whether OPWARMI available: |
| 238 |
|
|
| * if no: cold start: create OPWARMI |
| 239 |
|
|
| * if yes: warm start: read from OPWARMI |
| 240 |
|
|
| create or open OPWARMD |
| 241 |
|
|
| |
| 242 |
|
|
|---- check consistency between OPWARMI and model parameters |
| 243 |
|
|
| |
| 244 |
|
|
|---- >>> if COLD start: <<< |
| 245 |
|
|
| | first simulation with f.g. xx_0; output: first ff_0, gg_0 |
| 246 |
|
|
| | set first preconditioner value xdiff_0 to 1 |
| 247 |
|
|
| | store xx(0), gg(0), xdiff(0) to OPWARMD (first 3 entries) |
| 248 |
|
|
| | |
| 249 |
|
|
| >>> else: WARM start: <<< |
| 250 |
|
|
| read xx(i), gg(i) from OPWARMD (first 2 entries) |
| 251 |
|
|
| for first warm start after cold start, i=0 |
| 252 |
|
|
| |
| 253 |
|
|
| |
| 254 |
|
|
| |
| 255 |
|
|
|---- /// if ITMAX > 0: perform optimization (increment loop index i) |
| 256 |
|
|
| ( |
| 257 |
|
|
| )---- save current values of gg(i-1) -> gold(i-1), ff -> fold(i-1) |
| 258 |
|
|
| (---- CALL LSUPDXX |
| 259 |
|
|
| ) | |
| 260 |
|
|
| ( |---- >>> if jmax=0 <<< |
| 261 |
|
|
| ) | | first optimization after cold start: |
| 262 |
|
|
| ( | | preconditioner estimated via ff_0 - ff_(first guess) |
| 263 |
|
|
| ) | | dd(i-1) = -gg(i-1)*preco |
| 264 |
|
|
| ( | | |
| 265 |
|
|
| ) | >>> if jmax > 0 <<< |
| 266 |
|
|
| ( | dd(i-1) = -gg(i-1) |
| 267 |
|
|
| ) | CALL HESSUPD |
| 268 |
|
|
| ( | | |
| 269 |
|
|
| ) | |---- dd(i-1) modified via Hessian approx. |
| 270 |
|
|
| ( | |
| 271 |
|
|
| ) |---- >>> if <dd,gg> >= 0 <<< |
| 272 |
|
|
| ( | ifail = 4 |
| 273 |
|
|
| ) | |
| 274 |
|
|
| ( |---- compute step size: tact(i-1) |
| 275 |
|
|
| ) |---- compute update: xdiff(i) = xx(i-1) + tact(i-1)*dd(i-1) |
| 276 |
|
|
| ( |
| 277 |
|
|
| )---- >>> if ifail = 4 <<< |
| 278 |
|
|
| ( goto 1000 |
| 279 |
|
|
| ) |
| 280 |
|
|
| (---- CALL OPTLINE / LSLINE |
| 281 |
|
|
| ) | |
| 282 |
|
|
... ... ... |
| 283 |
|
|
\end{verbatim} |
| 284 |
|
|
} |
| 285 |
heimbach |
1.1 |
\caption{Flow chart (part 1 of 3)} |
| 286 |
|
|
\label{fig:lsoptflow1} |
| 287 |
|
|
\end{figure} |
| 288 |
|
|
|
| 289 |
adcroft |
1.3 |
\begin{figure} |
| 290 |
|
|
%\input{part8/lsopt_flow_2} |
| 291 |
|
|
{\scriptsize |
| 292 |
|
|
\begin{verbatim} |
| 293 |
|
|
... ... |
| 294 |
|
|
| ) |
| 295 |
|
|
| (---- CALL OPTLINE / LSLINE |
| 296 |
|
|
| ) | |
| 297 |
|
|
| ( |---- /// loop over simulations |
| 298 |
|
|
| ) ( |
| 299 |
|
|
| ( )---- CALL SIMUL |
| 300 |
|
|
| ) ( | |
| 301 |
|
|
| ( ) |---- input: xdiff(i) |
| 302 |
|
|
| ) ( |---- output: ff(i), gg(i) |
| 303 |
|
|
| ( ) |---- >>> if ONLINE <<< |
| 304 |
|
|
| ) ( runs model and adjoint |
| 305 |
|
|
| ( ) >>> if OFFLINE <<< |
| 306 |
|
|
| ) ( reads those values from file |
| 307 |
|
|
| ( ) |
| 308 |
|
|
| ) (---- 1st Wolfe test: |
| 309 |
|
|
| ( ) ff(i) <= tact*xpara1*<gg(i-1),dd(i-1)> |
| 310 |
|
|
| ) ( |
| 311 |
|
|
| ( )---- 2nd Wolfe test: |
| 312 |
|
|
| ) ( <gg(i),dd(i-1)> >= xpara2*<gg(i-1),dd(i-1)> |
| 313 |
|
|
| ( ) |
| 314 |
|
|
| ) (---- >>> if 1st and 2nd Wolfe tests ok <<< |
| 315 |
|
|
| ( ) | 320: update xx: xx(i) = xdiff(i) |
| 316 |
|
|
| ) ( | |
| 317 |
|
|
| ( ) >>> else if 1st Wolfe test not ok <<< |
| 318 |
|
|
| ) ( | 500: INTERpolate new tact: |
| 319 |
|
|
| ( ) | barr*tact < tact < (1-barr)*tact |
| 320 |
|
|
| ) ( | CALL CUBIC |
| 321 |
|
|
| ( ) | |
| 322 |
|
|
| ) ( >>> else if 2nd Wolfe test not ok <<< |
| 323 |
|
|
| ( ) 350: EXTRApolate new tact: |
| 324 |
|
|
| ) ( (1+barmin)*tact < tact < 10*tact |
| 325 |
|
|
| ( ) CALL CUBIC |
| 326 |
|
|
| ) ( |
| 327 |
|
|
| ( )---- >>> if new tact > tmax <<< |
| 328 |
|
|
| ) ( | ifail = 7 |
| 329 |
|
|
| ( ) | |
| 330 |
|
|
| ) (---- >>> if new tact < tmin OR tact*dd < machine precision <<< |
| 331 |
|
|
| ( ) | ifail = 8 |
| 332 |
|
|
| ) ( | |
| 333 |
|
|
| ( )---- >>> else <<< |
| 334 |
|
|
| ) ( update xdiff for new simulation |
| 335 |
|
|
| ( ) |
| 336 |
|
|
| ) \\\ if nfunc > 1: use inter-/extrapolated tact and xdiff |
| 337 |
|
|
| ( for new simulation |
| 338 |
|
|
| ) N.B.: new xx is thus not based on new gg, but |
| 339 |
|
|
| ( rather on new step size tact |
| 340 |
|
|
| ) |
| 341 |
|
|
| (---- store new values xx(i), gg(i) to OPWARMD (first 2 entries) |
| 342 |
|
|
| )---- >>> if ifail = 7,8,9 <<< |
| 343 |
|
|
| ( goto 1000 |
| 344 |
|
|
| ) |
| 345 |
|
|
... ... |
| 346 |
|
|
\end{verbatim} |
| 347 |
|
|
} |
| 348 |
heimbach |
1.1 |
\caption{Flow chart (part 2 of 3)} |
| 349 |
|
|
\label{fig:lsoptflow2} |
| 350 |
|
|
\end{figure} |
| 351 |
|
|
|
| 352 |
adcroft |
1.3 |
\begin{figure} |
| 353 |
|
|
%\input{part8/lsopt_flow_3} |
| 354 |
|
|
{\scriptsize |
| 355 |
|
|
\begin{verbatim} |
| 356 |
|
|
... ... |
| 357 |
|
|
| ) |
| 358 |
|
|
| (---- store new values xx(i), gg(i) to OPWARMD (first 2 entries) |
| 359 |
|
|
| )---- >>> if ifail = 7,8,9 <<< |
| 360 |
|
|
| ( goto 1000 |
| 361 |
|
|
| ) |
| 362 |
|
|
| (---- compute new pointers jmin, jmax to include latest values |
| 363 |
|
|
| ) gg(i)-gg(i-1), xx(i)-xx(i-1) to Hessian matrix estimate |
| 364 |
|
|
| (---- store gg(i)-gg(i-1), xx(i)-xx(i-1) to OPWARMD |
| 365 |
|
|
| ) (entries 2*jmax+2, 2*jmax+3) |
| 366 |
|
|
| ( |
| 367 |
|
|
| )---- CALL DGSCALE |
| 368 |
|
|
| ( | |
| 369 |
|
|
| ) |---- call dostore |
| 370 |
|
|
| ( | | |
| 371 |
|
|
| ) | |---- read preconditioner of previous iteration diag(i-1) |
| 372 |
|
|
| ( | from OPWARMD (3rd entry) |
| 373 |
|
|
| ) | |
| 374 |
|
|
| ( |---- compute new preconditioner diag(i), based upon diag(i-1), |
| 375 |
|
|
| ) | gg(i)-gg(i-1), xx(i)-xx(i-1) |
| 376 |
|
|
| ( | |
| 377 |
|
|
| ) |---- call dostore |
| 378 |
|
|
| ( | |
| 379 |
|
|
| ) |---- write new preconditioner diag(i) to OPWARMD (3rd entry) |
| 380 |
|
|
| ( |
| 381 |
|
|
|---- \\\ end of optimization iteration loop |
| 382 |
|
|
| |
| 383 |
|
|
| |
| 384 |
|
|
| |
| 385 |
|
|
|---- CALL OUTSTORE |
| 386 |
|
|
| | |
| 387 |
|
|
| |---- store gnorm0, ff(i), current pointers jmin, jmax, iterabs to OPWARMI |
| 388 |
|
|
| |
| 389 |
|
|
|---- >>> if OFFLINE version <<< |
| 390 |
|
|
| xx(i+1) needs to be computed as input for offline optimization |
| 391 |
|
|
| | |
| 392 |
|
|
| |---- CALL LSUPDXX |
| 393 |
|
|
| | | |
| 394 |
|
|
| | |---- compute dd(i), tact(i) -> xdiff(i+1) = x(i) + tact(i)*dd(i) |
| 395 |
|
|
| | |
| 396 |
|
|
| |---- CALL WRITE_CONTROL |
| 397 |
|
|
| | | |
| 398 |
|
|
| | |---- write xdiff(i+1) to special file for offline optim. |
| 399 |
|
|
| |
| 400 |
|
|
|---- print final information |
| 401 |
|
|
| |
| 402 |
|
|
O |
| 403 |
|
|
\end{verbatim} |
| 404 |
|
|
} |
| 405 |
heimbach |
1.1 |
\caption{Flow chart (part 3 of 3)} |
| 406 |
|
|
\label{fig:lsoptflow3} |
| 407 |
|
|
\end{figure} |
| 408 |
|
|
|