diff options
author | Michaël Baudin <michael.baudin@scilab.org> | 2009-10-07 16:25:30 +0200 |
---|---|---|
committer | Michaël Baudin <michael.baudin@scilab.org> | 2009-10-07 16:25:30 +0200 |
commit | 89a15e1086db0924450049b86f2a42a373fceed0 (patch) | |
tree | 8fd06dfb646f5a92a5812ae47bda44987f093b4b /scilab_doc | |
parent | 29c70e013b8e05b4309f62c95cef00ba2b8d272a (diff) | |
parent | 1169d8bb14b8fc5e8e4a3da183998134ad679bed (diff) | |
download | scilab-89a15e1086db0924450049b86f2a42a373fceed0.zip scilab-89a15e1086db0924450049b86f2a42a373fceed0.tar.gz |
Merge branch 'master' of git.scilab.org:scilab
Diffstat (limited to 'scilab_doc')
-rw-r--r-- | scilab_doc/neldermead/fminsearch-so.pdf | bin | 108029 -> 204275 bytes | |||
-rw-r--r-- | scilab_doc/neldermead/fminsearch.tex | 444 | ||||
-rw-r--r-- | scilab_doc/neldermead/macros.tex | 73 | ||||
-rw-r--r-- | scilab_doc/neldermead/neldermead.bib | 18 | ||||
-rw-r--r-- | scilab_doc/neldermead/scripts/fminsearch_rosenbrock.m | 26 | ||||
-rw-r--r-- | scilab_doc/neldermead/scripts/fminsearch_rosenbrock.sce | 32 | ||||
-rw-r--r-- | scilab_doc/neldermead/testFminsearchOptimplotfvalMatlab.png | bin | 0 -> 6249 bytes | |||
-rw-r--r-- | scilab_doc/neldermead/testFminsearchOptimplotfvalScilab.png | bin | 0 -> 4682 bytes | |||
-rw-r--r-- | scilab_doc/neldermead/testFminsearchPlotMatlab.png | bin | 2928 -> 3391 bytes | |||
-rw-r--r-- | scilab_doc/neldermead/testFminsearchPlotScilab.png | bin | 3183 -> 3517 bytes |
10 files changed, 585 insertions, 8 deletions
diff --git a/scilab_doc/neldermead/fminsearch-so.pdf b/scilab_doc/neldermead/fminsearch-so.pdf index 6604bc16..5f05ac7 100644 --- a/scilab_doc/neldermead/fminsearch-so.pdf +++ b/scilab_doc/neldermead/fminsearch-so.pdf | |||
Binary files differ | |||
diff --git a/scilab_doc/neldermead/fminsearch.tex b/scilab_doc/neldermead/fminsearch.tex index 85dac9f..9209dff 100644 --- a/scilab_doc/neldermead/fminsearch.tex +++ b/scilab_doc/neldermead/fminsearch.tex | |||
@@ -78,13 +78,64 @@ In this section, we analyse the behaviour of Scilab's \scifunction{fminsearch} | |||
78 | function, by comparison of Matlab's \scifunction{fminsearch}. We especially analyse | 78 | function, by comparison of Matlab's \scifunction{fminsearch}. We especially analyse |
79 | the results of the optimization, so that we can check that the algorithm | 79 | the results of the optimization, so that we can check that the algorithm |
80 | is indeed behaving the same way, even if the implementation is completely | 80 | is indeed behaving the same way, even if the implementation is completely |
81 | different. Our test case is based on Rosenbrock's function. | 81 | different. |
82 | |||
83 | We consider the unconstrained optimization problem \cite{citeulike:1903787} | ||
84 | \begin{eqnarray} | ||
85 | \min f(\bx) | ||
86 | \end{eqnarray} | ||
87 | where $\bx\in\RR^2$ and the objective function $f$ is defined by | ||
88 | \begin{eqnarray} | ||
89 | f(\bx) = 100*(x_2-x_1^2)^2+(1-x_1)^2. | ||
90 | \end{eqnarray} | ||
91 | The initial guess is | ||
92 | \begin{eqnarray} | ||
93 | \bx^0 = ( -1.2 , 1.)^T, | ||
94 | \end{eqnarray} | ||
95 | where the function value is | ||
96 | \begin{eqnarray} | ||
97 | f(\bx^0) = 24.2. | ||
98 | \end{eqnarray} | ||
99 | The global solution of this problem is | ||
100 | \begin{eqnarray} | ||
101 | \bx^\star = ( 1 , 1.)^T | ||
102 | \end{eqnarray} | ||
103 | where the function value is | ||
104 | \begin{eqnarray} | ||
105 | f(\bx^\star) = 0. | ||
106 | \end{eqnarray} | ||
107 | |||
108 | \subsection{Algorithm and numerical precision} | ||
109 | |||
110 | In this section, we are concerned by the comparison of the behavior | ||
111 | of the two algorithms. We are going to check that the algorithms | ||
112 | produces the same intermediate and final results. | ||
113 | We also analyze the numerical precision of the results, | ||
114 | by detailing the number of significant digits. | ||
115 | |||
116 | To make a more living presentation of this topic, we will | ||
117 | include small scripts which allow to produce the output | ||
118 | that we are going to analyze. Because of the similarity of the languages, | ||
119 | in order to avoid confusion, we will specify, for each script, the language | ||
120 | we use by a small comment. Scripts and outputs written in Matlab's language will begin with | ||
121 | \lstset{language=matlabscript} | ||
122 | \begin{lstlisting} | ||
123 | % Matlab | ||
124 | % ... | ||
125 | \end{lstlisting} | ||
126 | while script written in Scilab's language will begin with | ||
127 | \lstset{language=scilabscript} | ||
128 | \begin{lstlisting} | ||
129 | // Scilab | ||
130 | // ... | ||
131 | \end{lstlisting} | ||
82 | 132 | ||
83 | The following Matlab script allows to see the behaviour of Matlab's \scifunction{fminsearch} | 133 | The following Matlab script allows to see the behaviour of Matlab's \scifunction{fminsearch} |
84 | function on Rosenbrock's test case. | 134 | function on Rosenbrock's test case. |
85 | 135 | ||
86 | \lstset{language=scilabscript} | 136 | \lstset{language=matlabscript} |
87 | \begin{lstlisting} | 137 | \begin{lstlisting} |
138 | % Matlab | ||
88 | format long | 139 | format long |
89 | banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2; | 140 | banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2; |
90 | [x,fval,exitflag,output] = fminsearch(banana,[-1.2, 1]) | 141 | [x,fval,exitflag,output] = fminsearch(banana,[-1.2, 1]) |
@@ -94,8 +145,9 @@ output.message | |||
94 | When this script is launched in Matlab, the following output is | 145 | When this script is launched in Matlab, the following output is |
95 | produced. | 146 | produced. |
96 | 147 | ||
97 | \lstset{language=scilabscript} | 148 | \lstset{language=matlabscript} |
98 | \begin{lstlisting} | 149 | \begin{lstlisting} |
150 | >> % Matlab | ||
99 | >> format long | 151 | >> format long |
100 | >> banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2; | 152 | >> banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2; |
101 | >> [x,fval] = fminsearch(banana,[-1.2, 1]) | 153 | >> [x,fval] = fminsearch(banana,[-1.2, 1]) |
@@ -125,6 +177,7 @@ The following Scilab script allows to solve the problem with Scilab's | |||
125 | 177 | ||
126 | \lstset{language=scilabscript} | 178 | \lstset{language=scilabscript} |
127 | \begin{lstlisting} | 179 | \begin{lstlisting} |
180 | // Scilab | ||
128 | format(25) | 181 | format(25) |
129 | function y = banana (x) | 182 | function y = banana (x) |
130 | y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; | 183 | y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; |
@@ -137,6 +190,7 @@ The output associated with this Scilab script is the following. | |||
137 | 190 | ||
138 | \lstset{language=scilabscript} | 191 | \lstset{language=scilabscript} |
139 | \begin{lstlisting} | 192 | \begin{lstlisting} |
193 | -->// Scilab | ||
140 | -->format(25) | 194 | -->format(25) |
141 | -->function y = banana (x) | 195 | -->function y = banana (x) |
142 | --> y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; | 196 | --> y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; |
@@ -163,11 +217,102 @@ The output associated with this Scilab script is the following. | |||
163 | !and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-004 ! | 217 | !and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-004 ! |
164 | \end{lstlisting} | 218 | \end{lstlisting} |
165 | 219 | ||
166 | The result is as close as possible to the result produced | 220 | Because the two softwares do not use the same formatting rules |
221 | to produce their outputs, we must perform additionnal checking | ||
222 | in order to check our results. | ||
223 | |||
224 | The following Scilab script displays the results with 16 significant digits. | ||
225 | |||
226 | \lstset{language=scilabscript} | ||
227 | \begin{lstlisting} | ||
228 | // Scilab | ||
229 | // Print the result with 15 significant digits | ||
230 | mprintf ( "%.15e" , fval ); | ||
231 | mprintf ( "%.15e %.15e" , x(1) , x(2) ); | ||
232 | \end{lstlisting} | ||
233 | |||
234 | The previous script produces the following output. | ||
235 | |||
236 | \lstset{language=scilabscript} | ||
237 | \begin{lstlisting} | ||
238 | -->// Scilab | ||
239 | -->mprintf ( "%.15e" , fval ); | ||
240 | 8.177661099387146e-010 | ||
241 | -->mprintf ( "%.15e %.15e" , x(1) , x(2) ); | ||
242 | 1.000022021783557e+000 1.000042219751771e+000 | ||
243 | \end{lstlisting} | ||
244 | |||
245 | These results are reproduced verbatim in the table | ||
246 | \ref{fig-fminsearch-comparison}. | ||
247 | |||
248 | \begin{figure}[htbp] | ||
249 | \begin{center} | ||
250 | \begin{tabular}{|l|l|l|} | ||
251 | \hline | ||
252 | Matlab Iterations & 85 &\\ | ||
253 | Scilab Iterations & 85 &\\ | ||
254 | \hline | ||
255 | Matlab Function Evaluations & 159 &\\ | ||
256 | Scilab Function Evaluations & 159 &\\ | ||
257 | \hline | ||
258 | Matlab $\bx^\star$ & 1.000022021783570 & 1.000042219751772 \\ | ||
259 | Scilab $\bx^\star$ & 1.000022021783557e+000 & 1.000042219751771e+000 \\ | ||
260 | \hline | ||
261 | Matlab $f(\bx^\star)$ & 8.177661197416674e-10 &\\ | ||
262 | Scilab $f(\bx^\star)$ & 8.177661099387146e-010 &\\ | ||
263 | \hline | ||
264 | \end{tabular} | ||
265 | \end{center} | ||
266 | \caption{Numerical experiment with Rosenbrock's function -- Comparison of | ||
267 | results produced by Matlab and Scilab.} | ||
268 | \label{fig-fminsearch-comparison} | ||
269 | \end{figure} | ||
270 | |||
271 | We must compute the common number of significant digits | ||
272 | in order to check the consistency of the results. | ||
273 | The following Scilab script computes the relative error | ||
274 | between Scilab and Matlab results. | ||
275 | |||
276 | \lstset{language=scilabscript} | ||
277 | \begin{lstlisting} | ||
278 | // Scilab | ||
279 | // Compare the result | ||
280 | xmb = [1.000022021783570 1.000042219751772 ]; | ||
281 | err = norm(x - xmb) / norm(xmb); | ||
282 | mprintf ( "Relative Error on x : %e\n", err ); | ||
283 | fmb = 8.177661197416674e-10; | ||
284 | err = abs(fval - fmb) / abs(fmb); | ||
285 | mprintf ( "Relative Error on f : %e\n", err ); | ||
286 | \end{lstlisting} | ||
287 | |||
288 | The previous script produces the following output. | ||
289 | |||
290 | \lstset{language=scilabscript} | ||
291 | \begin{lstlisting} | ||
292 | // Scilab | ||
293 | Relative Error on x : 9.441163e-015 | ||
294 | Relative Error on f : 1.198748e-008 | ||
295 | \end{lstlisting} | ||
296 | |||
297 | We must take into account for the floating point implementations | ||
298 | of both Matlab and Scilab. In both these numerical softwares, | ||
299 | double precision floating point numbers are used, i.e. the relative | ||
300 | precision is both these softwares is $\epsilon \approx 10^{-16}$. | ||
301 | That implies that there are approximately 16 significant digits. | ||
302 | Therefore, the relative error on $x$, which is equivalent to 15 | ||
303 | significant digits, is acceptable. | ||
304 | If we now consider the relative error on $f$, which is equivalent | ||
305 | to only 8 significant digits, that may sound as a problem. | ||
306 | This corresponds to the square root of the relative precision, | ||
307 | because $\sqrt{\epsilon} = \approx 10^{-8}$. | ||
308 | In fact, this is the best that we can expect from an optimization | ||
309 | algorithm (\cite{Brent73algorithmsfor,Gill81MurrayWright}). | ||
310 | |||
311 | Therefore, the result is as close as possible to the result produced | ||
167 | by Matlab. More specifically : | 312 | by Matlab. More specifically : |
168 | \begin{itemize} | 313 | \begin{itemize} |
169 | \item the optimum $x$ is the same up to 14 significant digits, | 314 | \item the optimum $x$ is the same up to 15 significant digits, |
170 | \item the function value at optimum is the same up to 9 significant digits, | 315 | \item the function value at optimum is the same up to 8 significant digits, |
171 | \item the number of iterations is the same, | 316 | \item the number of iterations is the same, |
172 | \item the number of function evaluations is the same, | 317 | \item the number of function evaluations is the same, |
173 | \item the exit flag is the same, | 318 | \item the exit flag is the same, |
@@ -175,6 +320,291 @@ by Matlab. More specifically : | |||
175 | display the same way). | 320 | display the same way). |
176 | \end{itemize} | 321 | \end{itemize} |
177 | 322 | ||
323 | The output of the two functions is the same. | ||
324 | We must now check that the algorithms performs the same way, | ||
325 | that is, produces the same intermediate steps. | ||
326 | |||
327 | The following Matlab script allows to get deeper information by printing a message at each iteration | ||
328 | with the "Display" option. | ||
329 | |||
330 | \lstset{language=matlabscript} | ||
331 | \begin{lstlisting} | ||
332 | % Matlab | ||
333 | opt = optimset('Display','iter'); | ||
334 | [x,fval,exitflag,output] = fminsearch(banana,[-1.2, 1] , opt ); | ||
335 | \end{lstlisting} | ||
336 | |||
337 | The previous script produces the following output. | ||
338 | |||
339 | \lstset{language=matlabscript} | ||
340 | \begin{lstlisting} | ||
341 | % Matlab | ||
342 | Iteration Func-count min f(x) Procedure | ||
343 | 0 1 24.2 | ||
344 | 1 3 20.05 initial simplex | ||
345 | 2 5 5.1618 expand | ||
346 | 3 7 4.4978 reflect | ||
347 | 4 9 4.4978 contract outside | ||
348 | 5 11 4.38136 contract inside | ||
349 | 6 13 4.24527 contract inside | ||
350 | 7 15 4.21762 reflect | ||
351 | 8 17 4.21129 contract inside | ||
352 | 9 19 4.13556 expand | ||
353 | 10 21 4.13556 contract inside | ||
354 | 11 23 4.01273 expand | ||
355 | 12 25 3.93738 expand | ||
356 | 13 27 3.60261 expand | ||
357 | 14 28 3.60261 reflect | ||
358 | 15 30 3.46622 reflect | ||
359 | 16 32 3.21605 expand | ||
360 | 17 34 3.16491 reflect | ||
361 | 18 36 2.70687 expand | ||
362 | 19 37 2.70687 reflect | ||
363 | 20 39 2.00218 expand | ||
364 | 21 41 2.00218 contract inside | ||
365 | 22 43 2.00218 contract inside | ||
366 | 23 45 1.81543 expand | ||
367 | 24 47 1.73481 contract outside | ||
368 | 25 49 1.31697 expand | ||
369 | 26 50 1.31697 reflect | ||
370 | 27 51 1.31697 reflect | ||
371 | 28 53 1.1595 reflect | ||
372 | 29 55 1.07674 contract inside | ||
373 | 30 57 0.883492 reflect | ||
374 | 31 59 0.883492 contract inside | ||
375 | 32 61 0.669165 expand | ||
376 | 33 63 0.669165 contract inside | ||
377 | 34 64 0.669165 reflect | ||
378 | 35 66 0.536729 reflect | ||
379 | 36 68 0.536729 contract inside | ||
380 | 37 70 0.423294 expand | ||
381 | 38 72 0.423294 contract outside | ||
382 | 39 74 0.398527 reflect | ||
383 | 40 76 0.31447 expand | ||
384 | 41 77 0.31447 reflect | ||
385 | 42 79 0.190317 expand | ||
386 | 43 81 0.190317 contract inside | ||
387 | 44 82 0.190317 reflect | ||
388 | 45 84 0.13696 reflect | ||
389 | 46 86 0.13696 contract outside | ||
390 | 47 88 0.113128 contract outside | ||
391 | 48 90 0.11053 contract inside | ||
392 | 49 92 0.10234 reflect | ||
393 | 50 94 0.101184 contract inside | ||
394 | 51 96 0.0794969 expand | ||
395 | 52 97 0.0794969 reflect | ||
396 | 53 98 0.0794969 reflect | ||
397 | 54 100 0.0569294 expand | ||
398 | 55 102 0.0569294 contract inside | ||
399 | 56 104 0.0344855 expand | ||
400 | 57 106 0.0179534 expand | ||
401 | 58 108 0.0169469 contract outside | ||
402 | 59 110 0.00401463 reflect | ||
403 | 60 112 0.00401463 contract inside | ||
404 | 61 113 0.00401463 reflect | ||
405 | 62 115 0.000369954 reflect | ||
406 | 63 117 0.000369954 contract inside | ||
407 | 64 118 0.000369954 reflect | ||
408 | 65 120 0.000369954 contract inside | ||
409 | 66 122 5.90111e-005 contract outside | ||
410 | 67 124 3.36682e-005 contract inside | ||
411 | 68 126 3.36682e-005 contract outside | ||
412 | 69 128 1.89159e-005 contract outside | ||
413 | 70 130 8.46083e-006 contract inside | ||
414 | 71 132 2.88255e-006 contract inside | ||
415 | 72 133 2.88255e-006 reflect | ||
416 | 73 135 7.48997e-007 contract inside | ||
417 | 74 137 7.48997e-007 contract inside | ||
418 | 75 139 6.20365e-007 contract inside | ||
419 | 76 141 2.16919e-007 contract outside | ||
420 | 77 143 1.00244e-007 contract inside | ||
421 | 78 145 5.23487e-008 contract inside | ||
422 | 79 147 5.03503e-008 contract inside | ||
423 | 80 149 2.0043e-008 contract inside | ||
424 | 81 151 1.12293e-009 contract inside | ||
425 | 82 153 1.12293e-009 contract outside | ||
426 | 83 155 1.12293e-009 contract inside | ||
427 | 84 157 1.10755e-009 contract outside | ||
428 | 85 159 8.17766e-010 contract inside | ||
429 | |||
430 | Optimization terminated: | ||
431 | the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-004 | ||
432 | and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-004 | ||
433 | \end{lstlisting} | ||
434 | |||
435 | The following Scilab script set the "Display" option to "iter" and | ||
436 | run the \scifunction{fminsearch} function. | ||
437 | |||
438 | \lstset{language=scilabscript} | ||
439 | \begin{lstlisting} | ||
440 | // Scilab | ||
441 | opt = optimset ( "Display" , "iter" ); | ||
442 | [x , fval , exitflag , output] = fminsearch ( banana , [-1.2 1] , opt ); | ||
443 | \end{lstlisting} | ||
444 | |||
445 | \lstset{language=scilabscript} | ||
446 | \begin{lstlisting} | ||
447 | // Scilab | ||
448 | Iteration Func-count min f(x) Procedure | ||
449 | 0 3 24.2 | ||
450 | 1 3 20.05 initial simplex | ||
451 | 2 5 5.161796 expand | ||
452 | 3 7 4.497796 reflect | ||
453 | 4 9 4.497796 contract outside | ||
454 | 5 11 4.3813601 contract inside | ||
455 | 6 13 4.2452728 contract inside | ||
456 | 7 15 4.2176247 reflect | ||
457 | 8 17 4.2112906 contract inside | ||
458 | 9 19 4.1355598 expand | ||
459 | 10 21 4.1355598 contract inside | ||
460 | 11 23 4.0127268 expand | ||
461 | 12 25 3.9373812 expand | ||
462 | 13 27 3.602606 expand | ||
463 | 14 28 3.602606 reflect | ||
464 | 15 30 3.4662211 reflect | ||
465 | 16 32 3.2160547 expand | ||
466 | 17 34 3.1649126 reflect | ||
467 | 18 36 2.7068692 expand | ||
468 | 19 37 2.7068692 reflect | ||
469 | 20 39 2.0021824 expand | ||
470 | 21 41 2.0021824 contract inside | ||
471 | 22 43 2.0021824 contract inside | ||
472 | 23 45 1.8154337 expand | ||
473 | 24 47 1.7348144 contract outside | ||
474 | 25 49 1.3169723 expand | ||
475 | 26 50 1.3169723 reflect | ||
476 | 27 51 1.3169723 reflect | ||
477 | 28 53 1.1595038 reflect | ||
478 | 29 55 1.0767387 contract inside | ||
479 | 30 57 0.8834921 reflect | ||
480 | 31 59 0.8834921 contract inside | ||
481 | 32 61 0.6691654 expand | ||
482 | 33 63 0.6691654 contract inside | ||
483 | 34 64 0.6691654 reflect | ||
484 | 35 66 0.5367289 reflect | ||
485 | 36 68 0.5367289 contract inside | ||
486 | 37 70 0.4232940 expand | ||
487 | 38 72 0.4232940 contract outside | ||
488 | 39 74 0.3985272 reflect | ||
489 | 40 76 0.3144704 expand | ||
490 | 41 77 0.3144704 reflect | ||
491 | 42 79 0.1903167 expand | ||
492 | 43 81 0.1903167 contract inside | ||
493 | 44 82 0.1903167 reflect | ||
494 | 45 84 0.1369602 reflect | ||
495 | 46 86 0.1369602 contract outside | ||
496 | 47 88 0.1131281 contract outside | ||
497 | 48 90 0.1105304 contract inside | ||
498 | 49 92 0.1023402 reflect | ||
499 | 50 94 0.1011837 contract inside | ||
500 | 51 96 0.0794969 expand | ||
501 | 52 97 0.0794969 reflect | ||
502 | 53 98 0.0794969 reflect | ||
503 | 54 100 0.0569294 expand | ||
504 | 55 102 0.0569294 contract inside | ||
505 | 56 104 0.0344855 expand | ||
506 | 57 106 0.0179534 expand | ||
507 | 58 108 0.0169469 contract outside | ||
508 | 59 110 0.0040146 reflect | ||
509 | 60 112 0.0040146 contract inside | ||
510 | 61 113 0.0040146 reflect | ||
511 | 62 115 0.0003700 reflect | ||
512 | 63 117 0.0003700 contract inside | ||
513 | 64 118 0.0003700 reflect | ||
514 | 65 120 0.0003700 contract inside | ||
515 | 66 122 0.0000590 contract outside | ||
516 | 67 124 0.0000337 contract inside | ||
517 | 68 126 0.0000337 contract outside | ||
518 | 69 128 0.0000189 contract outside | ||
519 | 70 130 0.0000085 contract inside | ||
520 | 71 132 0.0000029 contract inside | ||
521 | 72 133 0.0000029 reflect | ||
522 | 73 135 0.0000007 contract inside | ||
523 | 74 137 0.0000007 contract inside | ||
524 | 75 139 0.0000006 contract inside | ||
525 | 76 141 0.0000002 contract outside | ||
526 | 77 143 0.0000001 contract inside | ||
527 | 78 145 5.235D-08 contract inside | ||
528 | 79 147 5.035D-08 contract inside | ||
529 | 80 149 2.004D-08 contract inside | ||
530 | 81 151 1.123D-09 contract inside | ||
531 | 82 153 1.123D-09 contract outside | ||
532 | 83 155 1.123D-09 contract inside | ||
533 | 84 157 1.108D-09 contract outside | ||
534 | 85 159 8.178D-10 contract inside | ||
535 | |||
536 | Optimization terminated: | ||
537 | the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-004 | ||
538 | and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-004 | ||
539 | \end{lstlisting} | ||
540 | |||
541 | A close inspection at the data reveals that the two softwares produces | ||
542 | indeed the same intermediate results. | ||
543 | |||
544 | \subsection{Plot features} | ||
545 | |||
546 | In this section, we check that the plotting features of the | ||
547 | \scifunction{fminsearch} function are the same. | ||
548 | |||
549 | The following output function plots in the current graphic | ||
550 | window the value of the current parameter $\bx$. | ||
551 | To let Matlab load that script, save the content in a | ||
552 | .m file, in a directory known by Matlab. | ||
553 | |||
554 | \lstset{language=matlabscript} | ||
555 | \begin{lstlisting} | ||
556 | % Matlab | ||
557 | function stop = outfun(x, optimValues, state) | ||
558 | stop = false; | ||
559 | hold on; | ||
560 | plot(x(1),x(2),'.'); | ||
561 | drawnow | ||
562 | \end{lstlisting} | ||
563 | |||
564 | The following Matlab script allows to perform the optimization | ||
565 | so that the output function is called back at each iteration. | ||
566 | |||
567 | \lstset{language=matlabscript} | ||
568 | \begin{lstlisting} | ||
569 | % Matlab | ||
570 | options = optimset('OutputFcn', @outfun); | ||
571 | [x fval] = fminsearch(banana, [-1.2, 1], options) | ||
572 | \end{lstlisting} | ||
573 | |||
574 | This produces the plot which is presented in figure \ref{fig-fminsearch-matlab-outputfun}. | ||
575 | |||
576 | \begin{figure} | ||
577 | \begin{center} | ||
578 | \includegraphics[width=10cm]{testFminsearchPlotMatlab.png} | ||
579 | \end{center} | ||
580 | \caption{Plot produced by Matlab's fminsearch, with customized output function.} | ||
581 | \label{fig-fminsearch-matlab-outputfun} | ||
582 | \end{figure} | ||
583 | |||
584 | The following Scilab script sets the "OutputFcn" option and then calls | ||
585 | the \scifunction{fminsearch} in order to perform the optimization. | ||
586 | |||
587 | \lstset{language=scilabscript} | ||
588 | \begin{lstlisting} | ||
589 | // Scilab | ||
590 | function outfun ( x , optimValues , state ) | ||
591 | plot( x(1),x(2),'.'); | ||
592 | endfunction | ||
593 | opt = optimset ( "OutputFcn" , outfun); | ||
594 | [x fval] = fminsearch ( banana , [-1.2 1] , opt ); | ||
595 | \end{lstlisting} | ||
596 | |||
597 | The previous script produces the plot which is presented | ||
598 | in figure \ref{fig-fminsearch-scilab-outputfun}. | ||
599 | |||
600 | \begin{figure} | ||
601 | \begin{center} | ||
602 | \includegraphics[width=10cm]{testFminsearchPlotScilab.png} | ||
603 | \end{center} | ||
604 | \caption{Plot produced by Scilab's fminsearch, with customized output function.} | ||
605 | \label{fig-fminsearch-scilab-outputfun} | ||
606 | \end{figure} | ||
178 | 607 | ||
179 | %TODO : check that the iterations are the same | 608 | Except for the size of the dots (which can be configured in |
609 | both softwares), the graphics are exactly the same. | ||
180 | 610 | ||
diff --git a/scilab_doc/neldermead/macros.tex b/scilab_doc/neldermead/macros.tex index 9464b36..572dd39 100644 --- a/scilab_doc/neldermead/macros.tex +++ b/scilab_doc/neldermead/macros.tex | |||
@@ -227,6 +227,79 @@ | |||
227 | stringstyle=\bfseries | 227 | stringstyle=\bfseries |
228 | }[keywords,comments,strings]% | 228 | }[keywords,comments,strings]% |
229 | 229 | ||
230 | \lstdefinelanguage{matlabscript}% | ||
231 | {morekeywords={gt,lt,gt,lt,amp,abs,acos,acosh,acot,acoth,acsc,acsch,% | ||
232 | all,angle,ans,any,asec,asech,asin,asinh,atan,atan2,atanh,auread,% | ||
233 | auwrite,axes,axis,balance,bar,bessel,besselk,bessely,beta,% | ||
234 | betainc,betaln,blanks,bone,break,brighten,capture,cart2pol,% | ||
235 | cart2sph,caxis,cd,cdf2rdf,cedit,ceil,chol,cla,clabel,clc,clear,% | ||
236 | clf,clock,close,colmmd,Colon,colorbar,colormap,ColorSpec,colperm,% | ||
237 | comet,comet3,compan,compass,computer,cond,condest,conj,contour,% | ||
238 | contour3,contourc,contrast,conv,conv2,cool,copper,corrcoef,cos,% | ||
239 | cosh,cot,coth,cov,cplxpair,cputime,cross,csc,csch,csvread,% | ||
240 | csvwrite,cumprod,cumsum,cylinder,date,dbclear,dbcont,dbdown,% | ||
241 | dbquit,dbstack,dbstatus,dbstep,dbstop,dbtype,dbup,ddeadv,ddeexec,% | ||
242 | ddeinit,ddepoke,ddereq,ddeterm,ddeunadv,deblank,dec2hex,deconv,% | ||
243 | del2,delete,demo,det,diag,diary,diff,diffuse,dir,disp,dlmread,% | ||
244 | dlmwrite,dmperm,dot,drawnow,echo,eig,ellipj,ellipke,else,elseif,% | ||
245 | end,engClose,engEvalString,engGetFull,engGetMatrix,engOpen,% | ||
246 | engOutputBuffer,engPutFull,engPutMatrix,engSetEvalCallback,% | ||
247 | engSetEvalTimeout,engWinInit,eps,erf,erfc,erfcx,erfinv,error,% | ||
248 | errorbar,etime,etree,eval,exist,exp,expint,expm,expo,eye,fclose,% | ||
249 | feather,feof,ferror,feval,fft,fft2,fftshift,fgetl,fgets,figure,% | ||
250 | fill,fill3,filter,filter2,find,findstr,finite,fix,flag,fliplr,% | ||
251 | flipud,floor,flops,fmin,fmins,fopen,for,format,fplot,fprintf,% | ||
252 | fread,frewind,fscanf,fseek,ftell,full,function,funm,fwrite,fzero,% | ||
253 | gallery,gamma,gammainc,gammaln,gca,gcd,gcf,gco,get,getenv,% | ||
254 | getframe,ginput,global,gplot,gradient,gray,graymon,grid,griddata,% | ||
255 | gtext,hadamard,hankel,help,hess,hex2dec,hex2num,hidden,hilb,hist,% | ||
256 | hold,home,hostid,hot,hsv,hsv2rgb,if,ifft,ifft2,imag,image,% | ||
257 | imagesc,Inf,info,input,int2str,interp1,interp2,interpft,inv,% | ||
258 | invhilb,isempty,isglobal,ishold,isieee,isinf,isletter,isnan,% | ||
259 | isreal,isspace,issparse,isstr,jet,keyboard,kron,lasterr,lcm,% | ||
260 | legend,legendre,length,lin2mu,line,linspace,load,log,log10,log2,% | ||
261 | loglog,logm,logspace,lookfor,lower,ls,lscov,lu,magic,matClose,% | ||
262 | matDeleteMatrix,matGetDir,matGetFp,matGetFull,matGetMatrix,% | ||
263 | matGetNextMatrix,matGetString,matlabrc,matlabroot,matOpen,% | ||
264 | matPutFull,matPutMatrix,matPutString,max,mean,median,menu,mesh,% | ||
265 | meshc,meshgrid,meshz,mexAtExit,mexCallMATLAB,mexdebug,% | ||
266 | mexErrMsgTxt,mexEvalString,mexFunction,mexGetFull,mexGetMatrix,% | ||
267 | mexGetMatrixPtr,mexPrintf,mexPutFull,mexPutMatrix,mexSetTrapFlag,% | ||
268 | min,more,movie,moviein,mu2lin,mxCalloc,mxCopyCharacterToPtr,% | ||
269 | mxCopyComplex16ToPtr,mxCopyInteger4ToPtr,mxCopyPtrToCharacter,% | ||
270 | mxCopyPtrToComplex16,mxCopyPtrToInteger4,mxCopyPtrToReal8,% | ||
271 | mxCopyReal8ToPtr,mxCreateFull,mxCreateSparse,mxCreateString,% | ||
272 | mxFree,mxFreeMatrix,mxGetIr,mxGetJc,mxGetM,mxGetN,mxGetName,% | ||
273 | mxGetNzmax,mxGetPi,mxGetPr,mxGetScalar,mxGetString,mxIsComplex,% | ||
274 | mxIsFull,mxIsNumeric,mxIsSparse,mxIsString,mxIsTypeDouble,% | ||
275 | mxSetIr,mxSetJc,mxSetM,mxSetN,mxSetName,mxSetNzmax,mxSetPi,% | ||
276 | mxSetPr,NaN,nargchk,nargin,nargout,newplot,nextpow2,nnls,nnz,% | ||
277 | nonzeros,norm,normest,null,num2str,nzmax,ode23,ode45,orient,orth,% | ||
278 | pack,pascal,patch,path,pause,pcolor,pi,pink,pinv,plot,plot3,% | ||
279 | pol2cart,polar,poly,polyder,polyeig,polyfit,polyval,polyvalm,% | ||
280 | pow2,print,printopt,prism,prod,pwd,qr,qrdelete,qrinsert,quad,% | ||
281 | quad8,quit,quiver,qz,rand,randn,randperm,rank,rat,rats,rbbox,% | ||
282 | rcond,real,realmax,realmin,refresh,rem,reset,reshape,residue,% | ||
283 | return,rgb2hsv,rgbplot,rootobject,roots,rose,rosser,rot90,rotate,% | ||
284 | round,rref,rrefmovie,rsf2csf,save,saxis,schur,sec,sech,semilogx,% | ||
285 | semilogy,set,setstr,shading,sign,sin,sinh,size,slice,sort,sound,% | ||
286 | spalloc,sparse,spaugment,spconvert,spdiags,specular,speye,spfun,% | ||
287 | sph2cart,sphere,spinmap,spline,spones,spparms,sprandn,sprandsym,% | ||
288 | sprank,sprintf,spy,sqrt,sqrtm,sscanf,stairs,startup,std,stem,% | ||
289 | str2mat,str2num,strcmp,strings,strrep,strtok,subplot,subscribe,% | ||
290 | subspace,sum,surf,surface,surfc,surfl,surfnorm,svd,symbfact,% | ||
291 | symmmd,symrcm,tan,tanh,tempdir,tempname,terminal,text,tic,title,% | ||
292 | toc,toeplitz,trace,trapz,tril,triu,type,uicontrol,uigetfile,% | ||
293 | uimenu,uiputfile,unix,unwrap,upper,vander,ver,version,view,% | ||
294 | viewmtx,waitforbuttonpress,waterfall,wavread,wavwrite,what,% | ||
295 | whatsnew,which,while,white,whitebg,who,whos,wilkinson,wk1read,% | ||
296 | wk1write,xlabel,xor,ylabel,zeros,zlabel,zoom},% | ||
297 | sensitive,% | ||
298 | morecomment=[l]\%,% | ||
299 | basicstyle=\tiny,% | ||
300 | morestring=[m]'% | ||
301 | }[keywords,comments,strings]% | ||
302 | |||
230 | \usepackage{algorithmic} | 303 | \usepackage{algorithmic} |
231 | 304 | ||
232 | % To allow one bibliograph by chapter | 305 | % To allow one bibliograph by chapter |
diff --git a/scilab_doc/neldermead/neldermead.bib b/scilab_doc/neldermead/neldermead.bib index 3d6f69b..ca7d39a 100644 --- a/scilab_doc/neldermead/neldermead.bib +++ b/scilab_doc/neldermead/neldermead.bib | |||
@@ -491,3 +491,21 @@ PAGES = {2928} | |||
491 | pages = {1422--1428} | 491 | pages = {1422--1428} |
492 | } | 492 | } |
493 | 493 | ||
494 | @MISC{Brent73algorithmsfor, | ||
495 | author = {Richard P. Brent}, | ||
496 | title = {Algorithms for Minimization without Derivatives}, | ||
497 | year = {1973} | ||
498 | } | ||
499 | |||
500 | @book{Gill81MurrayWright, | ||
501 | address = {London}, | ||
502 | author = {Gill, P. E. and Murray, W. and Wright, M. H. }, | ||
503 | citeulike-article-id = {1055426}, | ||
504 | keywords = {bibtex-import}, | ||
505 | posted-at = {2007-01-20 09:02:15}, | ||
506 | priority = {2}, | ||
507 | publisher = {Academic Press}, | ||
508 | title = {Practical optimization}, | ||
509 | year = {1981} | ||
510 | } | ||
511 | |||
diff --git a/scilab_doc/neldermead/scripts/fminsearch_rosenbrock.m b/scilab_doc/neldermead/scripts/fminsearch_rosenbrock.m new file mode 100644 index 0000000..e1a3cc4 --- /dev/null +++ b/scilab_doc/neldermead/scripts/fminsearch_rosenbrock.m | |||
@@ -0,0 +1,26 @@ | |||
1 | % Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | ||
2 | % Copyright (C) 2008-2009 - Digiteo - Michael Baudin | ||
3 | % | ||
4 | % This file must be used under the terms of the CeCILL. | ||
5 | % This source file is licensed as described in the file COPYING, which | ||
6 | % you should have received as part of this distribution. The terms | ||
7 | % are also available at | ||
8 | % http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt | ||
9 | |||
10 | % Basic use | ||
11 | format long | ||
12 | banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2; | ||
13 | [x,fval,exitflag,output] = fminsearch(banana,[-1.2, 1]) | ||
14 | output.message | ||
15 | |||
16 | % Now check each iteration | ||
17 | opt = optimset('Display','iter'); | ||
18 | [x,fval,exitflag,output] = fminsearch(banana,[-1.2, 1] , opt ); | ||
19 | |||
20 | |||
21 | % Check that the output functions are OK | ||
22 | options = optimset('OutputFcn', @outfun); | ||
23 | [x fval] = fminsearch(banana, [-1.2, 1], options) | ||
24 | |||
25 | |||
26 | |||
diff --git a/scilab_doc/neldermead/scripts/fminsearch_rosenbrock.sce b/scilab_doc/neldermead/scripts/fminsearch_rosenbrock.sce index ae80978..1029015 100644 --- a/scilab_doc/neldermead/scripts/fminsearch_rosenbrock.sce +++ b/scilab_doc/neldermead/scripts/fminsearch_rosenbrock.sce | |||
@@ -1,10 +1,40 @@ | |||
1 | // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | ||
2 | // Copyright (C) 2008-2009 - Digiteo - Michael Baudin | ||
3 | // | ||
4 | // This file must be used under the terms of the CeCILL. | ||
5 | // This source file is licensed as described in the file COPYING, which | ||
6 | // you should have received as part of this distribution. The terms | ||
7 | // are also available at | ||
8 | // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt | ||
9 | |||
10 | // Basic use | ||
1 | format(25) | 11 | format(25) |
2 | function y = banana (x) | 12 | function y = banana (x) |
3 | y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; | 13 | y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; |
4 | endfunction | 14 | endfunction |
5 | [x , fval , exitflag , output] = fminsearch ( banana , [-1.2 1] ) | 15 | [x , fval , exitflag , output] = fminsearch ( banana , [-1.2 1] ) |
6 | output.message | 16 | output.message |
17 | // Print the result with 15 significant digits | ||
18 | mprintf ( "%.15e" , fval ); | ||
19 | mprintf ( "%.15e %.15e" , x(1) , x(2) ); | ||
20 | // Compare the result | ||
21 | xmb = [1.000022021783570 1.000042219751772 ]; | ||
22 | err = norm(x - xmb) / norm(xmb); | ||
23 | mprintf ( "Relative Error on x : %e\n", err ); | ||
24 | fmb = 8.177661197416674e-10; | ||
25 | err = abs(fval - fmb) / abs(fmb); | ||
26 | mprintf ( "Relative Error on f : %e\n", err ); | ||
27 | |||
28 | // Now check each iteration | ||
29 | opt = optimset ( "Display" , "iter" ); | ||
30 | [x , fval , exitflag , output] = fminsearch ( banana , [-1.2 1] , opt ); | ||
31 | |||
32 | // Check that the output functions are OK | ||
33 | function outfun ( x , optimValues , state ) | ||
34 | plot( x(1),x(2),'.'); | ||
35 | endfunction | ||
36 | opt = optimset ( "OutputFcn" , outfun); | ||
37 | [x fval] = fminsearch ( banana , [-1.2 1] , opt ); | ||
7 | 38 | ||
8 | // Now check the iterations | ||
9 | 39 | ||
10 | 40 | ||
diff --git a/scilab_doc/neldermead/testFminsearchOptimplotfvalMatlab.png b/scilab_doc/neldermead/testFminsearchOptimplotfvalMatlab.png new file mode 100644 index 0000000..32f528a --- /dev/null +++ b/scilab_doc/neldermead/testFminsearchOptimplotfvalMatlab.png | |||
Binary files differ | |||
diff --git a/scilab_doc/neldermead/testFminsearchOptimplotfvalScilab.png b/scilab_doc/neldermead/testFminsearchOptimplotfvalScilab.png new file mode 100644 index 0000000..ca1600a --- /dev/null +++ b/scilab_doc/neldermead/testFminsearchOptimplotfvalScilab.png | |||
Binary files differ | |||
diff --git a/scilab_doc/neldermead/testFminsearchPlotMatlab.png b/scilab_doc/neldermead/testFminsearchPlotMatlab.png index e78702c..09e3476 100644 --- a/scilab_doc/neldermead/testFminsearchPlotMatlab.png +++ b/scilab_doc/neldermead/testFminsearchPlotMatlab.png | |||
Binary files differ | |||
diff --git a/scilab_doc/neldermead/testFminsearchPlotScilab.png b/scilab_doc/neldermead/testFminsearchPlotScilab.png index 164d426..5408533 100644 --- a/scilab_doc/neldermead/testFminsearchPlotScilab.png +++ b/scilab_doc/neldermead/testFminsearchPlotScilab.png | |||
Binary files differ | |||