[scilab-Users] optimization : general question

Michaël Baudin michael.baudin at scilab.org
Fri Dec 3 10:58:43 CET 2010


Hi,

Thanks for your report : you just found a bug. In the tests which were 
done, the objective function was always defined, whatever x. I just 
created a bug report for this:

http://bugzilla.scilab.org/show_bug.cgi?id=8546

As a workaround, we may use the following method.
  * Use the -simplex0method = "randbounds" initial simplex so that the 
initial simplex is inside the bounds, by design.
  * Penalize the objective function, so that the objective function is 
always defined, but equal to infinity if the point is outside the bounds.

Notice how the additionnal input argument data is used to pass the 
bounds to the function.

function [ f , index , data ] = myquad ( x , index , data )
     mprintf("index=%d, x=[%.2f %.2f]\n",index,x(1),x(2))
     xmin = data(1)'
     xmax = data(2)'
     if ( or(x < xmin) | or(x > xmax) ) then
         f = %inf
     else
         f = x(1)^2 + x(2)^2
     end
endfunction
rand("seed" , 0)
x0 = [1.2 1.9].';
xmin = [1 1];
xmax = [2 2];
data = list(xmin,xmax);
nm = nmplot_new ();
nm = nmplot_configure(nm,"-numberofvariables",2);
nm = nmplot_configure(nm,"-function",myquad);
nm = nmplot_configure(nm,"-costfargument",data);
nm = nmplot_configure(nm,"-x0",x0);
nm = nmplot_configure(nm,"-method","box");
nm = nmplot_configure(nm,"-boundsmin",xmin);
nm = nmplot_configure(nm,"-boundsmax",xmax);
nm = nmplot_configure(nm,"-simplex0method","randbounds");
nm = nmplot_search(nm);
xcomp = nmplot_get(nm,"-xopt") // Should be [1 1]
fcomp = nmplot_get(nm,"-fopt") // Should be 2
nm = nmplot_destroy(nm);

But this is a workaround: as the algorithm is designed to manage bounds, 
defining the function outside the bounds is unacceptable.

A complete update of neldermead/fminsearch is planned in a future 
release: I will fix these issues there.

Best regards,

Michaël Baudin

PS
By the way, I discovered a similar issue for the management of nonlinear 
constraints:
http://bugzilla.scilab.org/show_bug.cgi?id=8547<http://bugzilla.scilab.org/show_bug.cgi?id=8549>
As I was using the function, I discovered various minor flaws:
<http://bugzilla.scilab.org/show_bug.cgi?id=8549>http://bugzilla.scilab.org/show_bug.cgi?id=8542
http://bugzilla.scilab.org/show_bug.cgi?id=8543
http://bugzilla.scilab.org/show_bug.cgi?id=8544
http://bugzilla.scilab.org/show_bug.cgi?id=8545
http://bugzilla.scilab.org/show_bug.cgi?id=8549

Le 30/11/2010 21:39, Paul CARRICO a écrit :
>
> Michaël,
>
> The calculations run with the code herebelllow ... nevertheless the 
> parameters do not remain in the range defined by the brackets nay it 
> leads to FEA failure !
>
> I suppose consequently they are too far from the optimized value isn't 
> it (or there's a problem in my code) ècould you confirm ?
>
> Regards
>
> Paul
>
> ##################################################################
>
> initial_parameters = [C10 C01]'; // BE CAREFUL : [C10 C01]' = 
> transposed matrix
>
> nm = nmplot_new ();
>
> nm = nmplot_configure(nm,"-numberofvariables",2);      // Number of 
> variables => C10 & C01
>
> nm = nmplot_configure(nm,"-function",optimization2);
>
> nm = nmplot_configure(nm,"-x0",initial_parameters);    // BE CAREFUL : 
> [C10 C01]' = transposed matrix
>
> nm = nmplot_configure(nm,"-method","box");             // box => 
> brackets are taken into account
>
> nm = nmplot_configure(nm,"-boundsmin",[0 0]);
>
> nm = nmplot_configure(nm,"-boundsmax",[1 1]);
>
> [nm,SSE] = nmplot_function(nm,initial_parameters);
>
> nm = nmplot_configure(nm,"-simplexfn","history.simplex.dat");
>
> #################################################################
>
> The inital value of the C10 parameters are :
>
>    - C10 = 0.0623844
>
>    - C01 = 0.01
>
> #########################################################
>
>             * C10 = 0.0623844
>
>             * C01 = 0.01
>
>             * SSE = 0.640828
>
> Optimization in progress (please wait) ...
>
> #########################################################
>
>             * C10 = 0.0623844
>
>             * C01 = 0.01
>
> -->mode(0);
>
> -->mode(0);
>
>             * SSE = 0.640828
>
> #########################################################
>
>             * C10 = 0.0623844
>
>             * C01 = 0.01
>
> -->mode(0);
>
> -->mode(0);
>
>             * SSE = 0.640828
>
> #########################################################
>
>             * C10 = 0.0623844
>
>             * C01 = 0.01
>
>             * SSE = 0.640828
>
> #########################################################
>
>             * C10 = 1.06238
>
>             * C01 = 0.01
>
>             * SSE = 3097.29
>
> #########################################################
>
>             * C10 = 0.0623844
>
>             * C01 = 1.01
>
>             * SSE = 1390.08
>
> #########################################################
>
>             * C10 = -1.23762
>
>             * C01 = 1.16
>
>             * SSE = 0.218768
>
> #########################################################
>
>             * C10 = 1e-006
>
>             * C01 = 1.16
>
>             * SSE = 1525.15
>
> #########################################################
>
>             * C10 = 0.143483
>
>             * C01 = -0.335
>
>             * SSE = 42.4482
>
> #########################################################
>
>             * C10 = 0.143483
>
>             * C01 = 1e-006
>
>             * SSE = 23.5783
>
> #########################################################
>
>             * C10 = 0.155648
>
>             * C01 = -1.3015
>
>             * SSE = 1807.92
>
> #########################################################
>
>             * C10 = 0.129291
>
>             * C01 = -0.648249
>
>             * SSE = 356.971
>
> #########################################################
>
>             * C10 = 0.129291
>
>             * C01 = 1e-006
>
>             * SSE = 16.6268
>
> #########################################################
>
>             * C10 = 0.0338986
>
>             * C01 = 0.0114998
>
>             * SSE = 0.56774
>
> #########################################################
>
>             * C10 = -0.0573523
>
>             * C01 = 0.0247235
>
>             * SSE = 18.4969
>
> #########################################################
>
>             * C10 = -0.00460543
>
>             * C01 = 0.0177367
>
>             * SSE = 4.48301
>
> #########################################################
>
>             * C10 = 1e-006
>
>             * C01 = 0.0177367
>
>             * SSE = 5.72026
>
> #########################################################
>
>             * C10 = 0.110724
>
>             * C01 = 0.00166708
>
>             * SSE = 9.75208
>
> #########################################################
>
>             * C10 = 0.0794328
>
>             * C01 = 0.0062085
>
>             * SSE = 2.50334
>
> #########################################################
>
>             * C10 = 0.00746278
>
>             * C01 = 0.0166538
>
>             * SSE = 4.02474
>
> #########################################################
>
>             * C10 = 0.0278021
>
>             * C01 = 0.0137018
>
>             * SSE = 1.00242
>
> #########################################################
>
>             * C10 = 0.0745827
>
>             * C01 = 0.00691242
>
>             * SSE = 1.80759
>
> #########################################################
>
>             * C10 = 0.0613621
>
>             * C01 = 0.00883117
>
>             * SSE = 0.494514
>
> #########################################################
>
>             * C10 = 0.02845
>
>             * C01 = 0.0103807
>
> * SSE = 1.18104
>
> #########################################################
>
>             * C10 = 0.0380402
>
>             * C01 = 0.0102731
>
> The .dat file is empty - The calculation stops
>
> !--error 4
>
> Variable non définie: displacement_
>
> at line      90 of function ccx_dat_file called by :
>
> at line      51 of function  called by :
>
> at line      57 of function optimbase_function called by :
>
> at line      23 of function _boxlinesearch called by :
>
> at line     106 of function neldermead_box called by :
>
> at line       8 of function neldermead_algo called by :
>
> at line      15 of function neldermead_search called by :
>
> at line       5 of function nmplot_search called by :
>
>   nm = nmplot_search(nm);                 // start
>
> at line      33 of exec file called by :
>
> exec('C:\ETUDE_CALCULIX\ccx_scilab\fitting_procedure2.sce', -1)
>
> -->exec('SCI/etc/scilab.quit','errcatch',-1);quit;
>
> *De :*Michaël Baudin [mailto:michael.baudin at scilab.org] 
> <mailto:[mailto:michael.baudin at scilab.org]>
> *Envoyé :* mardi 30 novembre 2010 14:00
> *À :* users at lists.scilab.org <mailto:users at lists.scilab.org>
> *Cc :* Carrico, Paul
> *Objet :* Re: [scilab-Users] optimization : general question
>
> Hi,
>
> There is no way to apply bounds to the parameters from the fminsearch 
> function. This is because the algorithm was mainly designed for 
> unconstrained optimization. Nevertheless, it is possible to apply them 
> with the lower level component that the fminsearch function uses, the 
> neldermead component. This is possible by projecting the parameters on 
> the bounds. This makes the simple degenerate on the bounds and, if not 
> far away from the optimum, let the simplex converge on the optimum.
>
> In order to find an example, please look, in Scilab v5.2.2, in the 
> demonstrations:
>
> ? > Scilab Demonstrations > Optimization and simulation > neldermead Box B
>
> This example is based on the problem B from the Box' paper. It is a 
> problem with 2 bounded parameters (see in attachment).
>
> In Scilab v5.3, I added some other examples. This includes a simple 
> problem with bounds and  Rosenbrock's post office problem, an 
> optimization with 3 parameters and linear constraints (see in 
> attachement). The simplest problem is the following:
>
>   function [ f , index ] = myquad ( x , index )
>     f = x(1)^2 + x(2)^2
>   endfunction
>   rand("seed" , 0)
>   x0 = [1.2 1.9].';
>   nm = nmplot_new ();
>   nm = nmplot_configure(nm,"-numberofvariables",2);
>   nm = nmplot_configure(nm,"-function",myquad);
>   nm = nmplot_configure(nm,"-x0",x0);
>   nm = nmplot_configure(nm,"-method","box");
>   nm = nmplot_configure(nm,"-boundsmin",[1 1]);
>   nm = nmplot_configure(nm,"-boundsmax",[2 2]);
>   nm = nmplot_search(nm);
>   xcomp = nmplot_get(nm,"-xopt") // Should be [1 1]
>   fcomp = nmplot_get(nm,"-fopt") // Should be 2
>   nm = nmplot_destroy(nm);
>
> This example is not provided in the help of neldermead (see bug 
> #7164): I will fix this in the next release.
>
> Best regards,
>
> Michaël
>
> PS
> http://bugzilla.scilab.org/show_bug.cgi?id=7164
>
> Le 30/11/2010 11:58, Carrico, Paul a écrit :
>
> Dear all,
>
> The purpose of this mail is to benefit from user feedback of Scilab 
> community ... even if my experience on optimization item is currently 
> rather limited, this study will significantly increase my own expertise.
>
> I'm currently working in linking a FEA code with Scilab to fit 
> parameters from tests (see attached fig - in red the steps realized in 
> Scilab ) :
>
> - On a single parameter I used with success the *_fminsearch_* 
> function (based on the simplex theory),
>
> - with 2 parameters, the calculated ran ... nevertheless the final 
> result is physically non applicable (need to bracket one of the values 
> for examples)
>
> Does somebody be experienced on such item ? what is the best Scilab 
> function ? Some advices in reading ?
>
> Thanks in advance
>
> Regards
>
> Paul
>
> imap://michael%2Ebaudin@imap.scilab.org:993/fetch%3EUID%3E.INBOX.Users%3E3068?header=quotebody&part=1.2&filename=image001.jpg
>
> --------------------------------------------------------------------------------
>   
>   
> Le présent mail et ses pièces jointes sont confidentiels et destinés à la personne ou aux personnes visée(s) ci-dessus. Si vous avez reçu cet e-mail par erreur, veuillez contacter immédiatement l'expéditeur et effacer le message de votre système. Toute divulgation, copie ou distribution de cet e-mail est strictement interdite.
>   
> This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please contact the sender and delete the email from your system. If you are not the named addressee you should not disseminate, distribute or copy this email.
>   
>   
>
>
>
>
> -- 
> Michaël Baudin
> Ingénieur de développement
> michael.baudin at scilab.org  <mailto:michael.baudin at scilab.org>
> -------------------------
> Consortium Scilab - Digiteo
> Domaine de Voluceau - Rocquencourt
> B.P. 105 - 78153 Le Chesnay Cedex
> Tel. : 01 39 63 56 87 - Fax : 01 39 63 55 94
>   


-- 
Michaël Baudin
Ingénieur de développement
michael.baudin at scilab.org
-------------------------
Consortium Scilab - Digiteo
Domaine de Voluceau - Rocquencourt
B.P. 105 - 78153 Le Chesnay Cedex
Tel. : 01 39 63 56 87 - Fax : 01 39 63 55 94


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20101203/50fc62e6/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 68092 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20101203/50fc62e6/attachment.jpe>


More information about the users mailing list