[Scilab-users] Optim & NelderMead use [closed]

Stéphane Mottelet stephane.mottelet at utc.fr
Mon Jan 16 10:45:05 CET 2017


Hi Paul,

your cost function

*f*= sqrt((val_lin - val_rac)^2);

hasn't  changed, since sqrt(x^2)=abs(x). What I meant before is replacing

*f*= abs(val_lin - val_rac);

by

*f*= (val_lin - val_rac)^2;

in order to make it differentiable. When using a non-differentiable cost 
function together with numderivative, it seems logical that tweaking the 
step size could artificially help convergence.

S.


Le 16/01/2017 à 10:30, Carrico, Paul a écrit :
>
> Hi all
>
> After  performing tests (and modifying the target function as it 
> should have been done first), I can better understand how to use 
> ‘optim’ and ‘Neldermead’ procedures.
>
> For my needs the mean flags are :
>
> -Step h in numderivative àusefull reading as “EE 221 Numerical 
> Computing" Scott Hudson
>
> -The threshold epsg in optim (%eps is the default value – such high 
> accuracy is not necessary for my application – furthermore using a 
> value such as 1e-5 leads to err=1 that is correct for checking)
>
> -Ditto for Nelder-Mead and ‘-tolfunrelative’ & ‘-tolxrelative’
> Now it works fine :-)
> Thanks all for the support
> Paul
>
> #####################################################################
>
> mode(0)
> clear
> globalcount_use;
> count_use= 0;
> /// ****/
> function*f*=_lineaire_(*x*, *a2*, *b2*)
> *f* = *a2***x*+*b2*;
> endfunction
> /// ****/
> function*g*=_racine_(*x*, *a1*, *b1*)
> *g* = sqrt(*a1***x*) + *b1*;
> endfunction
> /// ****/
> function*f*=_target_(*x*, *a1*, *b1*, *a2*, *b2*)
> val_lin= _lineaire_(*x*,*a2*,*b2*);
> val_rac = _racine_(*x*,*a1*,*b1*);
> *f*= sqrt((val_lin - val_rac)^2);
> global count_use;
> count_use = count_use +1;
> endfunction
> /// Cost function: /
> function[*f*, *g*, *ind*]=_cost_(*x*, *ind*, *a1*, *b1*, *a2*, *b2*)
> *f* = _target_(*x*);
> ///    g = numderivative(target, x.',order = 4); /
> *g* = _numderivative_(_target_, *x*.',1e-3, order = 4); /// 1E-3 => 
> see EE 221 "Numerical Computing" Scott Hudson /
> /// Study of the influence of h on the number of target function 
> calculation & the fopt accuracy:/
> /// (epsg = %eps here)/
> /// h = 1.e-1 => number = 220 & fopt = 2.242026e-05/
> /// h = 1.e-2 => number = 195 & fopt = 2.267564e-07/
> /// h = 1.e-3 => number = 170 & fopt = 2.189495e-09 ++++++/
> /// h = 1.e-4 => number = 190 & fopt = 1.941203e-11/
> /// h = 1.e-5 => number = 215 & fopt = 2.131628e-13/
> /// h = 1.e-6 => number = 235 & fopt = 0./
> /// h = 1.e-7 => number = 255 & fopt = 7.105427e-15/
> /// h = 1.e-8 => number = 275 & fopt = 0./
> endfunction
> /// *************************/
> /// optimisation with optim/
> initial_parameters= [10]
> lower_bounds= [0];
> upper_bounds= [1000];
> nocf= 1000; /// number max of call of f/
> niter= 1000; /// number max of iterations/
> a1= 30;
> b1= 2.5;
> a2= 1;
> b2= 2;
> epsg= 1e-5; /// gradient norm threshold (%eps by defaut) --> lead to 
> err = 1 !!!/
> ///epsg = %eps;     // lead to Err = 13/
> epsf= 0; ///threshold controlling decreasing of f (epsf = 0 by defaut)/
> costf= list (_cost_, a1, b1, a2, b2);
> [fopt,xopt, gopt, work, iters, evals, err] = 
> optim(costf,'b',lower_bounds,upper_bounds,initial_parameters,'qn','ar',nocf,niter,epsg,epsf);
> printf("Optimized value : %g\n",xopt);
> printf("min cost function value (should be as closed as possible to 0) 
> ; %e\n",fopt);
> printf('Number of calculations = %d !!!\n',count_use);
> /// Curves definition/
> x= _linspace_(0,50,1000)';
> plot_raci= _racine_(x,a1,b1);
> plot_lin= _lineaire_(x,a2,b2);
> _scf_(1);
> drawlater();
> xgrid(3);
> f= _gcf_();
> ///f /
> f.figure_size= [1000, 1000];
> f.background= color(255,255,255);
> a= _gca_();
> ///a /
> a.font_size= 2;
> a.x_label.text= "X axis" ;
> a.x_location="bottom";
> a.x_label.font_angle=0;
> a.x_label.font_size= 4;
> a.y_label.text= "Y axis";
> a.y_location="left";
> a.y_label.font_angle=-90;
> a.Y_label.font_size= 4;
> a.title.text= "Title";
> a.title.font_size= 5;
> a.line_style= 1;
> /// Curves plot/
> _plot_(x,plot_lin);
> e1= _gce_();
> p1= e1.children;
> p1.thickness= 1;
> p1.line_style= 1;
> p1.foreground= 3;
> _plot_(x,plot_raci);
> e2= _gce_();
> p2= e2.children;
> p2.thickness= 1;
> p2.line_style= 1;
> p2.foreground= 2;
> drawnow();
>
> */EXPORT CONTROL :
> /**Cet email ne contient pas de données techniques
> This email does not contain technical data*
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170116/f3287f90/attachment.htm>


More information about the users mailing list