1
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
2
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
4
<LANGUAGE>eng</LANGUAGE>
6
<TYPE>Scilab Function</TYPE>
7
<DATE>April 1993</DATE>
8
<SHORT_DESCRIPTION name="optim"> non-linear optimization routine</SHORT_DESCRIPTION>
10
<CALLING_SEQUENCE_ITEM>[f,xopt]=optim(costf,x0) </CALLING_SEQUENCE_ITEM>
11
<CALLING_SEQUENCE_ITEM>[f,[xopt,[gradopt,[work]]]]=optim(costf,[contr],x0,['algo'],[df0,[mem]], </CALLING_SEQUENCE_ITEM>
12
<CALLING_SEQUENCE_ITEM> [work],[stop],['in'],[imp=iflag]) </CALLING_SEQUENCE_ITEM>
17
<PARAM_NAME>costf</PARAM_NAME>
19
<SP>: external, i.e Scilab function list or string (<VERB>costf</VERB> is the cost function: see below its calling sequence (Scilab or Fortran)). See also external for details about external functions.</SP>
23
<PARAM_NAME>x0</PARAM_NAME>
25
<SP>: real vector (initial value of variable to be minimized).</SP>
29
<PARAM_NAME>f</PARAM_NAME>
31
<SP>: value of optimal cost (<VERB>f=costf(xopt)</VERB>)</SP>
35
<PARAM_NAME>xopt</PARAM_NAME>
37
<SP>: best value of <VERB>x</VERB> found.</SP>
41
<PARAM_NAME>contr</PARAM_NAME>
43
<SP>: <VERB>'b',binf,bsup</VERB> with <VERB>binf</VERB> and <VERB>bsup</VERB> real vectors with same dimension as <VERB>x0</VERB>. <VERB>binf</VERB> and <VERB>bsup</VERB> are lower and upper bounds on <VERB>x</VERB>.</SP>
47
<PARAM_NAME>"algo" </PARAM_NAME>
49
<SP>: <VERB>'qn'</VERB> or <VERB>'gc'</VERB> or <VERB>'nd'</VERB> . This string stands for quasi-Newton (default), conjugate gradient or non-differentiable respectively. Note that <VERB>'nd'</VERB> does not accept bounds on <VERB>x</VERB> ).</SP>
53
<PARAM_NAME>df0</PARAM_NAME>
55
<SP>: real scalar. Guessed decreasing of <VERB>f</VERB> at first iteration. (<VERB>df0=1</VERB> is the default value).</SP>
59
<PARAM_NAME>mem : </PARAM_NAME>
61
<SP>integer, number of variables used to approximate the Hessian, (<VERB>algo='gc' or 'nd'</VERB>). Default value is around 6.</SP>
65
<PARAM_NAME>stop</PARAM_NAME>
67
<SP>: sequence of optional parameters controlling the convergence of the algorithm. <VERB> stop= 'ar',nap, [iter [,epsg [,epsf [,epsx]]]]</VERB></SP>
70
<PARAM_NAME>"ar" </PARAM_NAME>
72
<SP>: reserved keyword for stopping rule selection defined as follows:</SP>
76
<PARAM_NAME>nap</PARAM_NAME>
78
<SP>: maximum number of calls to <VERB>costf</VERB> allowed.</SP>
82
<PARAM_NAME>iter</PARAM_NAME>
84
<SP>: maximum number of iterations allowed.</SP>
88
<PARAM_NAME>epsg</PARAM_NAME>
90
<SP>: threshold on gradient norm.</SP>
94
<PARAM_NAME>epsf</PARAM_NAME>
96
<SP>: threshold controlling decreasing of <VERB>f</VERB></SP>
100
<PARAM_NAME>epsx</PARAM_NAME>
102
<SP>: threshold controlling variation of <VERB>x</VERB>. This vector (possibly matrix) of same size as <VERB>x0</VERB> can be used to scale <VERB>x</VERB>.</SP>
109
<PARAM_NAME>"in" </PARAM_NAME>
111
<SP>: reserved keyword for initialization of parameters used when <VERB>costf</VERB> in given as a Fortran routine (see below).</SP>
115
<PARAM_NAME>"imp=iflag" </PARAM_NAME>
117
<SP>: named argument used to set the trace mode. <VERB>iflag=0</VERB> nothing (execpt errors) is reported, <VERB>iflag=1</VERB> initial and final reports, <VERB>iflag=2</VERB> adds a report per iteration, <VERB>iflag>2</VERB> add reports on linear search. Warning, most of these reports are written on the Scilab standard output.</SP>
121
<PARAM_NAME>gradopt</PARAM_NAME>
123
<SP>: gradient of <VERB>costf</VERB> at <VERB>xopt</VERB></SP>
127
<PARAM_NAME>work</PARAM_NAME>
129
<SP>: working array for hot restart for quasi-Newton method. This array is automatically initialized by <VERB>optim</VERB> when <VERB>optim</VERB> is invoked. It can be used as input parameter to speed-up the calculations.</SP>
136
Non-linear optimization routine for programs without constraints or with bound constraints:</P>
139
min costf(x) w.r.t x.
142
<P><VERB>costf</VERB> is an "external" i.e function, or list or Fortran routine (see "external").
143
This external must return <VERB>f</VERB> (<VERB>costf(x)</VERB>) and <VERB>g</VERB> (gradient of <VERB>costf</VERB>)
144
given <VERB>x</VERB>.</P>
146
If <VERB>costf</VERB> is a function, the calling sequence for <VERB>costf</VERB> must be:</P>
149
[f,g,ind]=costf(x,ind).
153
Here, <VERB>costf</VERB> is a function which returns <VERB>f</VERB>, value (real number) of
154
cost function at <VERB>x</VERB>, and <VERB>g</VERB>, gradient vector of cost function at <VERB>x</VERB>.
155
The variable <VERB>ind</VERB> is used by <VERB>optim</VERB> and is described below.</P>
157
If <VERB>ind=2</VERB> (resp. <VERB>3, 4</VERB>), <VERB>costf</VERB> must provide <VERB>f</VERB> (resp. <VERB>g, f</VERB> and <VERB>g</VERB>).</P>
159
If <VERB>ind=1</VERB> nothing is computed (used for display purposes only).</P>
161
On output, <VERB>ind<0</VERB> means that <VERB>f</VERB> cannot be evaluated at <VERB>x</VERB> and
162
<VERB>ind=0</VERB> interrupts the optimization.</P>
164
If <VERB>costf</VERB> is a character string, it refers to the name of a Fortran routine
165
which must be linked to Scilab (see examples in the routines <VERB>foptim.f</VERB>
166
and e.g. <VERB>genros.f</VERB> in the directory SCIDIR/default)</P>
168
Dynamic link of Fortran routine is also possible (help <VERB>link</VERB>).</P>
170
Here, the generic calling sequence for the Fortran subroutine is:
171
<VERB>function costf(ind,n,x,f,g,ti,tr,td)</VERB></P>
172
<P><VERB>ind</VERB> has the same meaning as above if set to <VERB>0,1,2</VERB> but the
173
values <VERB>ind=10</VERB> and <VERB>ind=11</VERB> are now valid.
174
These values are used for initializations (see below).</P>
175
<P><VERB>n</VERB> is the dimension of <VERB>x</VERB>, <VERB>x</VERB> is an <VERB>n</VERB> vector,
176
<VERB>ti,tr,td</VERB> are working arrays.</P>
178
The Fortran function <VERB>costf</VERB> must return <VERB>f</VERB> and the vector <VERB>g</VERB>,
179
given <VERB>x, ind, n, ti, tr, td</VERB>.</P>
181
If <VERB>costf</VERB> is given as a Fortran routine, it is possible to initialize
182
parameters or to send Scilab variables to this routine.</P>
184
This facility is managed by the parameter <VERB>'in</VERB>.</P>
186
If the string <VERB>'in'</VERB> is present, initialization is done by Fortran:
187
<VERB>optim</VERB> makes two calls to the Fortran function <VERB>costf</VERB>, once with
188
<VERB>ind=10</VERB> and once with <VERB>ind=11</VERB>. In this case, for <VERB>ind=10</VERB>,
189
<VERB>costf</VERB> must set the dimensions <VERB>nti, ntr, ntd</VERB> of <VERB>ti, tr, td</VERB>
190
in the <VERB>common/nird/nti, ntr, ntd</VERB> and, for <VERB>ind=11</VERB>, <VERB>costf</VERB>
191
must initialize the vectors <VERB>ti , tr, td</VERB> (integer vector, real vector,
192
double precision vector respectively).</P>
194
In the calling sequence of <VERB>optim</VERB>, the string <VERB>'in'</VERB> can be
195
replaced by <VERB>'ti', valti ,'td' , valtd</VERB>. Then, the Fortran function
196
<VERB>costf(ind, x, f, g, ti, tr, td)</VERB> is evaluated with <VERB>ti=valti</VERB>
197
and <VERB>td=valtd</VERB> whatever the value of <VERB>ind</VERB>.
198
Thus, the Scilab variables <VERB>valti</VERB> and <VERB>valtd</VERB> (integer vector and
199
real vector) are sent to the Fortran function <VERB>costf</VERB>.</P>
201
It is also possible to save the content of of the working arrays
202
<VERB>ti</VERB> and <VERB>td</VERB>. This is possible by adding the strings 'si' and/or 'sd'
203
at the ned of the calling sequence of <VERB>optim</VERB>.
204
Then, the output variables must be: <VERB>[f,[x,[g],[to]]],[ti],[td]]</VERB>.</P>
208
xref=[1;2;3];x0=[1;-1;1]
209
deff('[f,g,ind]=cost(x,ind)','f=0.5*norm(x-xref)^2,g=x-xref');
210
[f,xopt]=optim(cost,x0) //Simplest call
211
[f,xopt,gopt]=optim(cost,x0,'gc') // By conjugate gradient
212
[f,xopt,gopt]=optim(cost,x0,'nd') //Seen as non differentiable
213
[f,xopt,gopt]=optim(cost,'b',[-1;0;2],[0.5;1;4],x0) // Bounds on x
214
[f,xopt,gopt]=optim(cost,'b',[-1;0;2],[0.5;1;4],x0,'gc') // Bounds on x
215
[f,xopt,gopt]=optim(cost,'b',[-1;0;2],[0.5;1;4],x0,'gc','ar',3)
216
// Here, 3 calls to cost are allowed.
217
// Now calling the Fortran subroutine "genros" in SCIDIR/default/Ex-optim.f
218
// See also the link function for dynamically linking an objective function
219
[f,xopt,gopt]=optim('genros',[1;2;3]) //Rosenbrock's function
224
<LINK>external</LINK>
242
<LINK>derivative</LINK>