Søren Hauberg wrote:
fre, 21 05 2010 kl. 09:53 +0200, skrev Alois Schlögl:
Søren Hauberg wrote:
lør, 20 03 2010 kl. 19:36 +0100, skrev Michael Creel:
I think that replacing list with cell arrays is pretty
straightforward. I did that for samin and bfgsmin quite a while ago,
when lists were deprecated. I suggest that the authors of the
functions in question take care of this before Octave 3.4 appears. If
they don't, then functions that stop working can be moved to a "deep
freeze" directory, so that they can be recovered when someone has time
to work on them.
This is fine by me.

The following functions seem to be using lists at the moment. Unless
they are fixed by the time Octave 3.4 is released, they will be put in a
directory that is not installed as part of the package.

        d2_min.m
        fminunc_compat.m
        line_min.m
        minimize.m
        nelder_mead_min.m
        test_d2_min_2.m
        test_d2_min_3.m
        test_fminunc_1.m
        test_min_3.m
        test_min_4.m
        test_minimize_1.m
        test_nelder_mead_min_1.m
        deriv.m
        optimset_compat.m
        __semi_bracket.m

So, if you care about any of these functions, please speak up.

I've replaced all list elements in optim. According to my tests, these tests work fine:
      test_d2_min_1         %   ok
      test_d2_min_2         %   ok
      test_d2_min_3         %   ok
      test_nelder_mead_min_2%   ok
      test_wpolyfit         %   ok
      test_min_3            %   ok

I guess, this means that most other functions (like d2_min, line_min, deriv, minimize, nelder_mead_min, and fminunc_compat are also fine. )

The following tests are still failing
      test_min_4            % ffailed
      test_minimize_1       %  failed
      test_nelder_mead_min_1%  failed
      test_fminunc_1        %  failed

test_min_4 fails with the following usage error:
usage: bfgsmin: 1st element of 3rd argument (iteration limit) must be Inf or positive integer.
Perhaps, this test is broken?
The other tests fail with a segmentation fault - so there is at least a problem somewhere else, too.

Is it ok to commit this these changes ?

Sorry about the late reply.

Could you please post the changes you are suggesting (the actual diff's)
to this list?


I've committed the changes already in r7326, so others (e.g. Michael) can see and test against them. The diff is attached.


Alois






Søren


Index: main/optim/inst/__semi_bracket.m
===================================================================
--- main/optim/inst/__semi_bracket.m	(revision 7325)
+++ main/optim/inst/__semi_bracket.m	(revision 7326)
@@ -1,7 +1,7 @@
 ## [a, b, ga, gb, nev] = semi_bracket (f, dx, a, narg, args)
 ##
 ## Find an interval containing a local minimum of the function 
-## g : h in [a, inf[ ---> f (x+h*dx) where x = nth (args, narg)
+## g : h in [a, inf[ ---> f (x+h*dx) where x = args{narg}
 ##
 ## The local minimum may be in a.
 ## a < b.
@@ -15,7 +15,7 @@
 
 step = 1;
 
-x = nth (args, narg);
+x = args{narg};
 args{narg} =  x+a*dx; ga = feval (f, args );
 b = a + step;
 args{narg} =  x+b*dx; gb = feval (f, args );
Index: main/optim/inst/test_d2_min_2.m
===================================================================
--- main/optim/inst/test_d2_min_2.m	(revision 7325)
+++ main/optim/inst/test_d2_min_2.m	(revision 7326)
@@ -84,7 +84,7 @@
 
 if verbose, printf ( "Going to call d2_min()\n"); end
 mytic() ;
-[xlev,vlev,nev] = d2_min ("ff", "d2ff", list (xinit,y), ctl) ;
+[xlev,vlev,nev] = d2_min ("ff", "d2ff", {xinit,y}, ctl) ;
 tlev = mytic ();
 
 if verbose,
Index: main/optim/inst/test_d2_min_3.m
===================================================================
--- main/optim/inst/test_d2_min_3.m	(revision 7325)
+++ main/optim/inst/test_d2_min_3.m	(revision 7326)
@@ -75,7 +75,7 @@
   printf ( "Going to call d2_min\n");
 end
 mytic() ;
-[xlev,vlev,nev] = d2_min ("ff", "d2ff", list (xinit,y),ctl) ;
+[xlev,vlev,nev] = d2_min ("ff", "d2ff", {xinit,y},ctl) ;
 tlev = mytic ();
 
 if verbose,
Index: main/optim/inst/de_min.m
===================================================================
--- main/optim/inst/de_min.m	(revision 7325)
+++ main/optim/inst/de_min.m	(revision 7326)
@@ -1,3 +1,4 @@
+
 ## Copyright (C) 2009 Christian Fischer <cfisc...@itm.uni-stuttgart.de>
 ## Copyright (C) 1996, 1997 R. Storn
 ##
@@ -147,7 +148,7 @@
   if nargin > 2,
     ctl = struct (varargin{:});
   else
-    ctl = nth (varargin, va_arg_cnt++);
+    ctl = varargin{va_arg_cnt++};
   end
   if isnumeric (ctl)
     if length (ctl)>=1 && !isnan (ctl(1)), XVmin  = ctl(1); end
@@ -455,3 +456,4 @@
 %! ## and solve it with de_min
 %! [x, obj_value, nfeval, convergence] = de_min (f, ctl)
 
+
Index: main/optim/inst/nelder_mead_min.m
===================================================================
--- main/optim/inst/nelder_mead_min.m	(revision 7325)
+++ main/optim/inst/nelder_mead_min.m	(revision 7326)
@@ -65,7 +65,7 @@
 ##
 ##                { x + e_i | i in 0..N } 
 ## 
-##                Where x == nth (args, narg) is the initial value 
+##                Where x == args{narg} is the initial value 
 ##                 e_0    == zeros (size (x)), 
 ##                 e_i(j) == 0 if j != i and e_i(i) == ctl(5)
 ##                 e_i    has same size as x
@@ -100,7 +100,11 @@
 
 if nargin >= 3,			# Read control arguments
   va_arg_cnt = 1;
-  if nargin > 3, ctl = struct (varargin{:}); else ctl = nth (varargin, va_arg_cnt++); end
+  if nargin > 3, 
+          ctl = struct (varargin{:}); 
+  else 
+          ctl = varargin{va_arg_cnt++}; 
+  end
   if isnumeric (ctl)
     if length (ctl)>=1 && !isnan (ctl(1)), crit = ctl(1); end
     if length (ctl)>=2 && !isnan (ctl(2)), tol = ctl(2); end
@@ -109,16 +113,16 @@
     if length (ctl)>=5 && !isnan (ctl(5)), isz = ctl(5); end
     if length (ctl)>=6 && !isnan (ctl(6)), rst = ctl(6); end
   else
-    if struct_contains (ctl, "crit") && ! isnan (ctl.crit ), crit  = ctl.crit ; end
-    if struct_contains (ctl,  "tol") && ! isnan (ctl.tol  ), tol   = ctl.tol  ; end
-    if struct_contains (ctl, "ftol") && ! isnan (ctl.ftol ), ftol  = ctl.ftol ; end
-    if struct_contains (ctl, "rtol") && ! isnan (ctl.rtol ), rtol  = ctl.rtol ; end
-    if struct_contains (ctl, "vtol") && ! isnan (ctl.vtol ), vtol  = ctl.vtol ; end
-    if struct_contains (ctl, "narg") && ! isnan (ctl.narg ), narg  = ctl.narg ; end
-    if struct_contains (ctl,"maxev") && ! isnan (ctl.maxev), maxev = ctl.maxev; end
-    if struct_contains (ctl,  "isz") && ! isnan (ctl.isz  ), isz   = ctl.isz  ; end
-    if struct_contains (ctl,  "rst") && ! isnan (ctl.rst  ), rst   = ctl.rst  ; end
-    if struct_contains(ctl,"verbose")&& !isnan(ctl.verbose),verbose=ctl.verbose;end
+    if isfield (ctl, "crit") && ! isnan (ctl.crit ), crit  = ctl.crit ; end
+    if isfield (ctl,  "tol") && ! isnan (ctl.tol  ), tol   = ctl.tol  ; end
+    if isfield (ctl, "ftol") && ! isnan (ctl.ftol ), ftol  = ctl.ftol ; end
+    if isfield (ctl, "rtol") && ! isnan (ctl.rtol ), rtol  = ctl.rtol ; end
+    if isfield (ctl, "vtol") && ! isnan (ctl.vtol ), vtol  = ctl.vtol ; end
+    if isfield (ctl, "narg") && ! isnan (ctl.narg ), narg  = ctl.narg ; end
+    if isfield (ctl,"maxev") && ! isnan (ctl.maxev), maxev = ctl.maxev; end
+    if isfield (ctl,  "isz") && ! isnan (ctl.isz  ), isz   = ctl.isz  ; end
+    if isfield (ctl,  "rst") && ! isnan (ctl.rst  ), rst   = ctl.rst  ; end
+    if isfield(ctl,"verbose")&& !isnan(ctl.verbose),verbose=ctl.verbose;end
   end
 end
 
@@ -131,15 +135,11 @@
 
 if iscell (args)
   x = args{1};
-elseif islist (args),		# List of arguments 
-  args = {args{:}};
-  x = args{1};
 else				# Single argument
   x = args;
   args = {args};
 endif
 
-
 if narg > length (args)		# Check
   error ("nelder_mead_min : narg==%i, length (args)==%i\n",
 	 narg, length (args));
@@ -152,10 +152,9 @@
 u = isz * eye (N+1,N) + ones(N+1,1)*x';
 
 y = zeros (N+1,1);
-
 for i = 1:N+1,
-  ##y(i) = leval (f, splice (args, narg, 1, list (reshape (u(i,:),R,C))));
-  y(i) = feval (f, {args{1:narg-1},reshape(u(i,:),R,C),args{narg+1:length(args)}}{:});
+  aa = {args{1:narg-1},reshape(u(i,:),R,C),args{narg+1:end}};
+  y(i) = feval (f, aa{:});
 end ;
 nev = N+1;
 
@@ -181,10 +180,14 @@
   
 				# Compute stopping criterion
   done = 0;
-  if ! isnan (ftol), done |= (max(y)-min(y)) / max(1,max(abs(y))) < ftol;end
-  if ! isnan (rtol), done |= 2*max (max (u) - min (u)) < rtol; end
+  if ! isnan (ftol), 
+     done |= ((max(y)-min(y)) / max(1,max(abs(y))) < ftol); 
+  end
+  if ! isnan (rtol), 
+     done = (2*max (max (u) - min (u)) < rtol); 
+  end
   if ! isnan (vtol)
-    done |= abs (det (u(1:N,:)-ones(N,1)*u(N+1,:)))/factorial(N) < vtol;
+    done |= (abs (det (u(1:N,:)-ones(N,1)*u(N+1,:)))/factorial(N) < vtol);
   end
   ## [ 2*max (max (u) - min (u)), abs (det (u(1:N,:)-ones(N,1)*u(N+1,:)))/factorial(N);\
   ##  rtol, vtol]
@@ -217,7 +220,6 @@
       u += jumplen * randn (size (u));
       for i = 1:N+1, y(i) = \
 	    feval (f, {args{1:narg-1},reshape(u(i,:),R,C),args{narg+1:length(args)}}{:});
-	## leval (f, splice (args, narg, 1, list (reshape (u(i,:),R,C))));	
       end
       nev += N+1;
       [ymin,imin] = min(y);  [ymax,imax] = max(y);
@@ -249,7 +251,6 @@
   ## f2 = f1 - (-1)  = 2/N + 1 = (N+2)/N
   xnew = (2*xsum - (N+2)*u(imax,:)) / N;
   ## xnew = (2*xsum - N*u(imax,:)) / N;
-  ## ynew = leval (f, splice (args, narg, 1, list ( reshape (xnew, R,C))));
   ynew = feval (f, {args{1:narg-1},reshape(xnew,R,C),args{narg+1:length(args)}}{:});
   nev++;
   
@@ -267,7 +268,6 @@
     ## f1 = (1-2)/N = -1/N
     ## f2 = f1 - 2  = -1/N - 2 = -(2*N+1)/N
     xnew = ( -xsum + (2*N+1)*u(imax,:) ) / N;
-    ##ynew = leval (f, splice (args, narg, 1, list ( reshape (xnew, R,C))));
     ynew = feval (f, {args{1:narg-1},reshape(xnew,R,C),args{narg+1:length(args)}}{:});
     nev++;
       
@@ -299,7 +299,6 @@
     ## f1 = (1-0.5)/N = 0.5/N
     ## f2 = f1 - 0.5  = 0.5*(1 - N)/N
     xnew = 0.5*(xsum + (N-1)*u(imax,:)) / N;
-    ##ynew = leval (f, splice (args, narg, 1, list (reshape (xnew, R,C))));
     ynew = feval (f, {args{1:narg-1},reshape(xnew,R,C),args{narg+1:length(args)}}{:});
     nev++;
 
@@ -318,7 +317,6 @@
       for i = ii
 	y(i) = \
 	    ynew = feval (f, {args{1:narg-1},reshape(u(i,:),R,C),args{narg+1:length(args)}}{:});
-	    ##leval (f, splice (args, narg, 1, list (reshape (u(i,:),R,C))));
       end
       ##      'contraction'
       tra += 16 ;
Index: main/optim/inst/test_min_3.m
===================================================================
--- main/optim/inst/test_min_3.m	(revision 7325)
+++ main/optim/inst/test_min_3.m	(revision 7326)
@@ -45,7 +45,7 @@
 ## global obses ;
 obses = obsmat*truep ;
 
-extra = list (obsmat, obses);
+extra = {obsmat, obses};
 
 
 function v = ff(x, obsmat, obses)
Index: main/optim/inst/test_min_4.m
===================================================================
--- main/optim/inst/test_min_4.m	(revision 7325)
+++ main/optim/inst/test_min_4.m	(revision 7326)
@@ -34,7 +34,7 @@
 
 function v = ff(x,y,t)
   A = [1 -1;1 1]; M = A'*diag([100,1])*A;
-  v = ((x - y)(1:2))'*M*((x-y)(1:2)) + 1;
+  v = (x(1:2) - y(1:2))'*M*(x(1:2)-y(1:2)) + 1;
 endfunction
 
 
@@ -42,7 +42,7 @@
   if nargin < 3, t = 1; end
   if t == 1, N = length (x); else N = length (y); end
   A = [1 -1;1 1]; M = A'*diag([100,1])*A;
-  dv = 2*((x-y)(1:2))'*M;
+  dv = 2*(x(1:2)-y(1:2))'*M;
   if N>2, dv = [dv, zeros(1,N-2)]; end
   if t == 2, dv = -dv; end
 endfunction
@@ -62,7 +62,7 @@
 
 ## Plain run, just to make sure ######################################
 ## Minimum wrt 'x' is y0
-## [xlev,vlev,nlev] = feval (optim_func, "ff", "dff", list (x0,y0,1));
+## [xlev,vlev,nlev] = feval (optim_func, "ff", "dff", {x0,y0,1});
 ## ctl.df = "dff";
 [xlev,vlev,nlev] = feval (optim_func, "ff", {x0,y0,1});
 
@@ -80,7 +80,6 @@
 ## ctl = struct ("narg", 2,"df","dff");
 ## ctl = [nan,nan,2];
 ## [xlev,vlev,nlev] = feval (optim_func, "ff", list (x0,y0,2),ctl);
-
 [xlev,vlev,nlev] = feval (optim_func, "ff", {x0,y0,2},{inf,0,1,2});
 
 cnt++;
@@ -96,7 +95,7 @@
 ## Minimum wrt 'x' is y0
 ## ctl = struct ("narg", 1,"verbose",verbose, "df", "dff");
 ## ctl = [nan,nan,2];
-## [xlev,vlev,nlev] = feval (optim_func, "ff", "dff", list (x0,y0,1),ctl);
+## [xlev,vlev,nlev] = feval (optim_func, "ff", "dff", {x0,y0,1},ctl);
 [xlev,vlev,nlev] = feval (optim_func, "ff", {x0,y0,1},{inf,1,1,1});
 
 cnt++;
Index: main/optim/inst/optimset_compat.m
===================================================================
--- main/optim/inst/optimset_compat.m	(revision 7325)
+++ main/optim/inst/optimset_compat.m	(revision 7326)
@@ -45,7 +45,7 @@
 
 				# Integrate all leading structs
 
-while length (args) && isstruct (o = nth (args, 1))
+while length (args) && isstruct (o = args{1})
 
   args = args(2:length(args)); 	# Remove 1st element of args
 				# Add key/value pairs
Index: main/optim/inst/d2_min.m
===================================================================
--- main/optim/inst/d2_min.m	(revision 7325)
+++ main/optim/inst/d2_min.m	(revision 7326)
@@ -1,3 +1,4 @@
+
 ## Copyright (C) 2002 Etienne Grossmann.  All rights reserved.
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -113,14 +114,14 @@
     if length (ctl)>=4 && !isnan (ctl(4)), maxev = ctl(4); end
     if length (ctl)>=5 && !isnan (ctl(5)), id2f  = ctl(5); end
   elseif isstruct (ctl)
-    if struct_contains (ctl, "crit")   , crit    = ctl.crit   ; end
-    if struct_contains (ctl, "tol")    , tol     = ctl.tol    ; end
-    if struct_contains (ctl, "narg")   , narg    = ctl.narg   ; end
-    if struct_contains (ctl, "maxev")  , maxev   = ctl.maxev  ; end
-    if struct_contains (ctl, "maxout") , maxout  = ctl.maxout ; end
-    if struct_contains (ctl, "id2f")   , id2f    = ctl.id2f   ; end
-    if struct_contains (ctl, "verbose"), verbose = ctl.verbose; end
-    if struct_contains (ctl, "code")   , code    = ctl.code   ; end
+    if isfield (ctl, "crit")   , crit    = ctl.crit   ; end
+    if isfield (ctl, "tol")    , tol     = ctl.tol    ; end
+    if isfield (ctl, "narg")   , narg    = ctl.narg   ; end
+    if isfield (ctl, "maxev")  , maxev   = ctl.maxev  ; end
+    if isfield (ctl, "maxout") , maxout  = ctl.maxout ; end
+    if isfield (ctl, "id2f")   , id2f    = ctl.id2f   ; end
+    if isfield (ctl, "verbose"), verbose = ctl.verbose; end
+    if isfield (ctl, "code")   , code    = ctl.code   ; end
   else 
     error ("The 'ctl' argument should be either a vector or a struct");
   end
@@ -135,11 +136,11 @@
 
 if nargin < 5, code = "" ; end
 
-if is_list (args)		# List of arguments 
-  x = nth (args, narg);
+if iscell (args)		# List of arguments 
+  x = args{narg};
 else				# Single argument
   x = args;
-  args = list (args); 
+  args = {args}; 
 end
 
 ############################## Checking ##############################
@@ -158,7 +159,7 @@
 
 sz = size (x); N = prod (sz);
 
-v = leval (f, args);
+v = feval (f, args{:});
 nev = [1,0];
 
 if prudent && (! isnumeric (v) || isnan (v) || any (size (v)>1))
@@ -173,9 +174,11 @@
     printf ( "d2_min : Initially, v=%8.3g\n",v);
 end
 
-while niter++ <= maxout && nev(1) < maxev
+while niter <= maxout
+  niter += 1;
+  if nev(1) < maxev, break; end;  
 
-  [v,d,h] = leval (d2f, splice (args, narg, 1, list (reshape (x,sz))));
+  [v,d,h] = feval (d2f, {args{1:narg-1},reshape(x,sz),args{narg+1:end}}{:}); 
   nev(2)++;
 
   if prudent && niter <= 1 && \
@@ -189,7 +192,7 @@
   d = d(:);
 
   if prudent
-    v2 = leval (f, splice (args, narg, 1, list (reshape (x,sz))));
+    v2 = feval (f, {args{1:narg-1},reshape(x,sz),args{narg+1:end}}{:});
     nev(1)++;
     if abs(v2-v) > 0.001 * sqrt(eps) * max (abs(v2), 1)
       printf ("d2_min : f and d2f disagree %8.3g\n",abs(v2-v));
@@ -224,11 +227,12 @@
   wn = 1 ;			# Weight of Newton step
   wt = 1 ;			# Total weight
   
-  ninner = done_inner = 0;	# 0=not found. 1=Ready to quit inner.
+  ninner = 0; 
+  done_inner = 0;	# 0=not found. 1=Ready to quit inner.
   
 				# ##########################################
-  while ninner++ < maxinner	# Inner loop ###############################
-
+  while ninner < maxinner,	# Inner loop ###############################
+    ninner += 1;
 				# Proposed step
     dx = wt*(wn*dnewton - (1-wn)*d) ;
     xnew = x+dx ;
@@ -242,8 +246,8 @@
       printf ("d2_min : Whoa!! any(isnan(xnew)) (1)\n"); 
     end
 
-    vnew = leval (f, splice (args, narg, 1, list (reshape (xnew,sz))));
-    nev(1)++ ;
+    vnew = feval (f, {args{1:narg-1},reshape(xnew,sz),args{narg+1:end}}{:});
+    nev(1)++;
 
     if vnew<vbest		# Stash best values
       dbest = dx ; 
@@ -281,7 +285,7 @@
     if any(isnan(xnew)),
       printf ("d2_min : Whoa!! any(isnan(xnew)) (2)\n"); 
     end
-    vnew = leval (f, splice (args, narg, 1, list (reshape (xnew,sz))));
+    vnew = feval (f, {args{1:narg-1},reshape(xnew,sz),args{narg+1:end}}{:});
     nev(1)++;
 
     while vnew < vbest,
@@ -290,7 +294,7 @@
       xbest = xnew; 
       wn = wn*ocoeff ;
       xnew = x+wn*dbest;
-      vnew = leval (f, splice (args, narg, 1, list (reshape (xnew,sz))));
+      vnew = feval (f, {args{1:narg-1},reshape(xnew,sz),args{narg+1:length(args)}}{:});
       if verbose
           printf ( "Looking farther : v = %8.3g\n",vnew);
       end
@@ -315,7 +319,7 @@
   if vbest < vold
     ## "improvement found"
     if prudent
-      tmpv = leval (f, splice (args, narg, 1, list (reshape (xbest,sz))));
+      tmpv = feval (f, {args{1:narg-1},reshape(xbest,sz),args{2:end}}{:});
       nev(1)++;
 
       if abs (tmpv-vbest) > eps
@@ -338,8 +342,8 @@
       abest = args;
 				# Check whether eval (code) changes value
       if prudent
-	tmpv = leval (f, splice (args, narg, 1, list (reshape (x,sz))));
-	nev(1)++;
+        tmpv = feval (f, {args{1:narg-1},reshape(x,sz),args{2:end}}{:});
+        nev(1)++;
 	if abs (tmpv-vbest) > max (min (100*eps,0.00001*abs(vbest)), eps) ,
 	  printf ("d2_min : Whoa! Value changes by %g after eval (code)\n",\
 		  abs (tmpv-vbest));
@@ -382,7 +386,7 @@
 
 				# One last check
 if prudent
-  err = leval (f, splice (args, narg, 1, list (reshape (xbest,sz))));
+  err = feval (f, {args{1:narg-1},reshape(xbest,sz),args{2:end}}{:});
   nev(1)++;
 
   if abs (err-vbest) > eps,
@@ -390,3 +394,4 @@
     printf ("       : %8.3e - %8.3e = %8.3e != 0\n",err,vbest,err-vbest);
   end
 end
+
Index: main/optim/inst/wpolyfit.m
===================================================================
--- main/optim/inst/wpolyfit.m	(revision 7325)
+++ main/optim/inst/wpolyfit.m	(revision 7326)
@@ -1,3 +1,4 @@
+
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {...@var{p}, @var{s}] =} wpolyfit (@var{x}, @var{y}, @var{dy}, @var{n})
 ## Return the coefficients of a polynomial @var{p}(@var{x}) of degree
@@ -33,7 +34,7 @@
 ##
 ## You can use a chi^2 test to reject the polynomial fit:
 ## @example
-## p = 1-chisquare_cdf(s.normr^2,s.df);
+## p = 1-chi2cdf(s.normr^2,s.df);
 ## @end example
 ## p is the probability of seeing a chi^2 value higher than that which 
 ## was observed assuming the data are normally distributed around the fit.
@@ -177,7 +178,7 @@
   endif
 
   if nargout == 0
-    good_fit = 1-chisquare_cdf(s.normr^2,s.df);
+    good_fit = 1-chi2cdf(s.normr^2,s.df);
     printf("Polynomial: %s  [ p(chi^2>observed)=%.2f%% ]\n", polyout(p,'x'), good_fit*100);
     plt(x,y,dy,p,s,'ci');
   else
@@ -259,3 +260,4 @@
 %! printf ("Original polynomial: %s\n", polyout (pin, 'x'));
 %! wpolyfit (x, y, dy, length (pin)-1);
 
+
Index: main/optim/inst/test_nelder_mead_min_1.m
===================================================================
--- main/optim/inst/test_nelder_mead_min_1.m	(revision 7325)
+++ main/optim/inst/test_nelder_mead_min_1.m	(revision 7326)
@@ -1,3 +1,4 @@
+
 ## Copyright (C) 2002 Etienne Grossmann.  All rights reserved.
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -36,17 +37,17 @@
 end
 
 function c = my_quad_func (x,y,z)
-  c = 1 + sum ((x-y)(:)'*z*((x-y)(:)));
+  c = 1 + sum (vec(x-y)'*z*(vec(x-y)));
 end
 
 function c = non_quad_func_1 (x,y,z)
-  tmp = sum ((x-y)(:)'*z*((x-y)(:)));
+  tmp = sum (vec(x-y)'*z*(vec(x-y)));
   c = 1 + 1.1*tmp + sin (sqrt(tmp));
 end
 
 function c = non_quad_func_2 (x,y,z)
-  tmp1 = sum ((x-y)(:)'*z*((x-y)(:)));
-  tmp2 = max (abs ((x-y)(:)))^2;
+  tmp1 = sum (vec(x-y)'*z*(vec(x-y)));
+  tmp2 = max (abs (vec(x-y)))^2;
   c = 1 + 1.1*tmp1 + tmp2 ;
 end
 
@@ -61,21 +62,21 @@
    last_mytic = t ;
 endfunction
 
-fnames = list ( "my_quad_func", "non_quad_func_1", "non_quad_func_2");
+fnames = { "my_quad_func", "non_quad_func_1", "non_quad_func_2"};
 
 x0 = randn(R,C) ;
 x1 = x0 + randn(R,C) ;
 z = randn (R*C); z = z*z';
 
 for i = 1:length (fnames)
-  fname = nth (fnames, i);
+  fname = fnames{i};
   if verbose, 
     printf ("trying to minimize '%s'\n", fname);
   end
   ctl = nan*zeros (1,6);
 
   mytic ();
-  [x2,v,nf] = nelder_mead_min (fname, list (x1,x0,z), ctl) ;
+  [x2,v,nf] = nelder_mead_min (fname, {x1,x0,z}, ctl) ;
   t0 = mytic ();
 
   if any (abs (x2-x0)(:) > 100*tol),
@@ -92,7 +93,7 @@
 
 				# Use vanilla nelder_mead_min
   mytic ();
-  [x2,v,nf] = nelder_mead_min (fname, list (x1,x0,z)) ;
+  [x2,v,nf] = nelder_mead_min (fname, {x1,x0,z}) ;
   t1 = mytic ();
 
   if any (abs (x2-x0)(:) > 100*tol),
@@ -114,7 +115,7 @@
   ctl(3) = 2;
 
   mytic ();
-  [x2,v,nf] = nelder_mead_min (fname, list (x1,x0,z), ctl) ;
+  [x2,v,nf] = nelder_mead_min (fname, {x1,x0,z}, ctl) ;
   t0 = mytic ();
 
   if any (abs (x2-x1)(:) > 100*tol),
@@ -134,7 +135,7 @@
   ctl(3) = 2;
 
   mytic ();
-  [x2,v,nf] = nelder_mead_min (fname, list (x1,x0,z), ctl) ;
+  [x2,v,nf] = nelder_mead_min (fname, {x1,x0,z}, ctl) ;
   t1 = mytic ();
 
   if any (abs (x2-x1)(:) > tol),
@@ -151,7 +152,7 @@
   if 0
 				# Check with struct control variable
     ctls = struct ("narg", 2);
-    [x2bis,vbis,nfbis] = nelder_mead_min (fname, list (x1,x0,z), ctls) ;
+    [x2bis,vbis,nfbis] = nelder_mead_min (fname, {x1,x0,z}, ctls) ;
     t1 = mytic ();
     ## [nf,nfbis]
     if any ((x2-x2bis)(:))
@@ -167,7 +168,7 @@
     cnt++;
     
 				# Check with named args
-    [x2bis,vbis,nfbis] = nelder_mead_min (fname, list (x1,x0,z), "narg", 2) ;
+    [x2bis,vbis,nfbis] = nelder_mead_min (fname, {x1,x0,z}, "narg", 2) ;
     t1 = mytic ();
     ## [nf,nfbis]
     if any ((x2-x2bis)(:))
@@ -188,3 +189,4 @@
   printf ("All tests ok\n");
 end
 
+
Index: main/optim/inst/line_min.m
===================================================================
--- main/optim/inst/line_min.m	(revision 7325)
+++ main/optim/inst/line_min.m	(revision 7326)
@@ -47,13 +47,13 @@
 
   nev = 0;
   h = 0.001;			# Was 0.01 here
-  x = nth (args,narg);
+  x = args{narg};
   a = 0;
 				# was 1e-4
   while (abs (velocity) > 0.000001)
-    fx = leval (f,splice (args, narg, 1, list (x+a*dx)));
-    fxph = leval (f,splice (args, narg,1,list (x+(a+h)*dx)));
-    fxmh = leval (f,splice (args, narg,1,list (x+(a-h)*dx)));
+    fx = feval (f,{args{1:narg-1}, {x+a*dx}, args{narg+1:end}}{:});
+    fxmh = feval (f,{args{1:narg-1}, {x+(a+h)*dx}, args{narg+1:end}}{:});
+    fxmh = feval (f,{args{1:narg-1}, {x+(a-h)*dx}, args{narg+1:end}}{:});
 
     velocity = (fxph - fxmh)/(2*h);
     acceleration = (fxph - 2*fx + fxmh)/(h^2);
Index: main/optim/inst/expfit.m
===================================================================
--- main/optim/inst/expfit.m	(revision 7325)
+++ main/optim/inst/expfit.m	(revision 7326)
@@ -91,7 +91,7 @@
 a = log(u)/h;
 
 % Compose second matrix A(i,j) = u(j)^(i-1)
-A = ( ones(N,1) * u(:).' ) .^ ( [0:N-1](:) * ones(1,deg) );
+A = ( ones(N,1) * u(:).' ) .^ ( [0:N-1]' * ones(1,deg) );
 
 % Solve linear system
 f = A\y;
Index: main/optim/inst/test_minimize_1.m
===================================================================
--- main/optim/inst/test_minimize_1.m	(revision 7325)
+++ main/optim/inst/test_minimize_1.m	(revision 7326)
@@ -28,7 +28,7 @@
 ## Return value
 function v = ff(x,y,t)
   A = [1 -1;1 1]; M = A'*diag([100,1])*A;
-  v = ((x - y)(1:2))'*M*((x-y)(1:2)) + 1;
+  v = (x(1:2) - y(1:2))'*M*(x(1:2)-y(1:2)) + 1;
 endfunction
 
 ## Return differential
@@ -36,7 +36,7 @@
   if nargin < 3, t = 1; end
   if t == 1, N = length (x); else N = length (y); end
   A = [1 -1;1 1]; M = A'*diag([100,1])*A;
-  dv = 2*((x-y)(1:2))'*M;
+  dv = 2*(x(1:2)-y(1:2))'*M;
   if N>2, dv = [dv, zeros(1,N-2)]; end
   if t == 2, dv = -dv; end
 endfunction
@@ -46,8 +46,8 @@
   if nargin < 3, t = 1; end
   if t == 1, N = length (x); else N = length (y); end
   A = [1 -1;1 1]; M = A'*diag([100,1])*A;
-  v = ((x - y)(1:2))'*M*((x-y)(1:2)) + 1;
-  dv = 2*((x-y)(1:2))'*M;
+  v = (x(1:2) - y(1:2))'*M*(x(1:2)-y(1:2)) + 1;
+  dv = 2*(x(1:2)-y(1:2))'*M;
   d2v = zeros (N); d2v(1:2,1:2) = 2*M;
   if N>2, dv = [dv, zeros(1,N-2)]; end
   if t == 2, dv = -dv; end
@@ -58,8 +58,8 @@
   if nargin < 3, t = 1; end
   if t == 1, N = length (x); else N = length (y); end
   A = [1 -1;1 1]; M = A'*diag([100,1])*A;
-  v = ((x - y)(1:2))'*M*((x-y)(1:2)) + 1;
-  dv = 2*((x-y)(1:2))'*M;
+  v = (x(1:2) - y(1:2))'*M*(x(1:2)-y(1:2)) + 1;
+  dv = 2*(x(1:2)-y(1:2))'*M;
   d2v = zeros (N); d2v(1:2,1:2) = inv (2*M);
   if N>2, dv = [dv, zeros(1,N-2)]; end
   if t == 2, dv = -dv; end
@@ -77,7 +77,7 @@
 
 ## Plain run, just to make sure ######################################
 ## Minimum wrt 'x' is y0
-[xlev,vlev,nlev] = minimize ("ff",list (x0,y0,1));
+[xlev,vlev,nlev] = minimize ("ff",{x0,y0,1});
 
 cnt++;
 if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -89,7 +89,7 @@
 end
 
 ## See what 'backend' gives in that last case ########################
-[method,ctl] = minimize ("ff",list (x0,y0,1),"order",0,"backend");
+[method,ctl] = minimize ("ff",{x0,y0,1},"order",0,"backend");
 
 cnt++;
 if ! ischar (method) || ! strcmp (method,"nelder_mead_min")
@@ -105,7 +105,7 @@
 elseif verbose,  prn ("ok %i\n",cnt);
 end
 
-[xle2,vle2,nle2] = feval (method, "ff",list (x0,y0,1), ctl);
+[xle2,vle2,nle2] = feval (method, "ff", {x0,y0,1}, ctl);
 cnt++;
 				# nelder_mead_min is not very repeatable
 				# because of restarts from random positions
@@ -121,7 +121,7 @@
 ## Run, w/ differential, just to make sure ###########################
 ## Minimum wrt 'x' is y0
 
-# [xlev,vlev,nlev] = minimize ("ff",list (x0,y0,1),"df","dff");
+# [xlev,vlev,nlev] = minimize ("ff",{x0,y0,1},"df","dff");
 
 # cnt++;
 # if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -134,7 +134,7 @@
 
 ## Run, w/ differential returned by function ('jac' option) ##########
 ## Minimum wrt 'x' is y0
-# [xlev,vlev,nlev] = minimize ("d2ff",list (x0,y0,1),"jac");
+# [xlev,vlev,nlev] = minimize ("d2ff",{x0,y0,1},"jac");
 
 # cnt++;
 # if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -147,7 +147,7 @@
 
 ## Run, w/ 2nd differential, just to make sure #######################
 ## Minimum wrt 'x' is y0
-[xlev,vlev,nlev] = minimize ("ff",list (x0,y0,1),"d2f","d2ff");
+[xlev,vlev,nlev] = minimize ("ff",{x0,y0,1},"d2f","d2ff");
 
 cnt++;
 if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -160,7 +160,7 @@
 
 ## Use the 'hess' option, when f can return 2nd differential #########
 ## Minimum wrt 'x' is y0
-[xlev,vlev,nlev] = minimize ("d2ff",list (x0,y0,1),"hess");
+[xlev,vlev,nlev] = minimize ("d2ff", {x0,y0,1},"hess");
 
 cnt++;
 if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -173,7 +173,7 @@
 
 ## Run, w/ inverse of 2nd differential, just to make sure ############
 ## Minimum wrt 'x' is y0
-[xlev,vlev,nlev] = minimize ("ff",list (x0,y0,1),"d2i","d2iff");
+[xlev,vlev,nlev] = minimize ("ff", {x0,y0,1},"d2i","d2iff");
 
 cnt++;
 if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -186,7 +186,7 @@
 
 ## Use the 'ihess' option, when f can return pinv of 2nd differential 
 ## Minimum wrt 'x' is y0
-[xlev,vlev,nlev] = minimize ("d2iff",list (x0,y0,1),"ihess");
+[xlev,vlev,nlev] = minimize ("d2iff", {x0,y0,1},"ihess");
 
 cnt++;
 if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -199,7 +199,7 @@
 
 ## Run, w/ numerical differential ####################################
 ## Minimum wrt 'x' is y0
-[xlev,vlev,nlev] = minimize ("ff",list (x0,y0,1),"ndiff");
+[xlev,vlev,nlev] = minimize ("ff",{x0,y0,1},"ndiff");
 
 cnt++;
 if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -212,7 +212,7 @@
 
 ## Run, w/ numerical differential, specified by "order" ##############
 ## Minimum wrt 'x' is y0
-[xlev,vlev,nlev] = minimize ("ff",list (x0,y0,1),"order",1);
+[xlev,vlev,nlev] = minimize ("ff",{x0,y0,1},"order",1);
 
 cnt++;
 if max (abs (xlev-y0)) > 100*sqrt (eps)
@@ -224,7 +224,7 @@
 end
 
 # ## See what 'backend' gives in that last case ########################
-# [method,ctl] = minimize ("ff",list (x0,y0,1),"order",1,"backend");
+# [method,ctl] = minimize ("ff",{x0,y0,1},"order",1,"backend");
 
 # cnt++;
 # if ! strcmp (method,"bfgsmin")
@@ -235,8 +235,8 @@
 # elseif verbose,  prn ("ok %i\n",cnt);
 # end
 
-## [xle2,vle2,nle2] = feval (method, "ff",list (x0,y0,1), ctl);
-[xle2,vle2,nle2] = minimize ("ff",list (x0,y0,1),"order",1);
+## [xle2,vle2,nle2] = feval (method, "ff",{x0,y0,1}, ctl);
+[xle2,vle2,nle2] = minimize ("ff",{x0,y0,1},"order",1);
 cnt++;
 if max (abs (xlev-xle2)) > 100*eps
   if verbose
Index: main/optim/inst/fminunc_compat.m
===================================================================
--- main/optim/inst/fminunc_compat.m	(revision 7325)
+++ main/optim/inst/fminunc_compat.m	(revision 7326)
@@ -44,9 +44,9 @@
 
 if nargin < 3, opt = struct (); end
 if nargin > 3, 
-  args = list (x0, varargin{:});
+  args = {x0, varargin{:}};
 else 
-  args = list (x0);
+  args = {x0};
 end
 
 ## Do some checks ####################################################
@@ -67,7 +67,6 @@
     es = [es,sprintf("Unknown option '%s'\n",k)];
   end
 end
-
 ## Check for ignored options
 ## All ignored options
 iop = [" DerivativeCheck DiffMaxChange DiffMinChange",\
@@ -97,7 +96,7 @@
 		"Backend"    , "backend");
 
 for [v,k] = equiv
-  if struct_contains (opt,k)
+  if isfield (opt,k)
     opm = setfield (opm, getfield(equiv,k), getfield(opt,k));
   end
 end
@@ -115,23 +114,23 @@
 end
 
 unary_opt = " hess jac backend verbose ";
-opml = list ();
+opml = {};
 for [v,k] = opm
   if findstr ([" ",k," "], unary_opt)
-    opml = append (opml, list (k));
+    opml{end+1} = {k};
   else
-    opml = append (opml, list (k, v));
+    opml{end+1} = {k,v};
   end
 end
 				# Return only options to minimize() ##
-if struct_contains (opt, "MinEquiv")
+if isfield (opt, "MinEquiv")
   x = opml;			
   if nargout > 1
     warning ("Only 1 return value is defined with the 'MinEquiv' option");
   end
   return
 				# Use the backend option #############
-elseif struct_contains (opm, "backend")
+elseif isfield (opm, "backend")
   [x,fval] = minimize (fun, args, opml);
   if nargout > 2
     warning ("Only 2 return values are defined with the 'Backend' option");
@@ -140,17 +139,15 @@
 else  				# Do the minimization ################
   [x,fval,out] = minimize (fun, args, opml);
   
-  if struct_contains (opm, "maxev")
+  if isfield (opm, "maxev")
     flag = out(1) < getfield(opm,"maxev");
   else
     flag = 1;
   end
   
   if nargout > 4
-    args = splice (args, 1, 1, list (x));
-    [dummy,df,d2f] = leval (fun, args);
+    [dummy,df,d2f] = feval (fun, x, args{2:end});
   elseif nargout > 3
-    args = splice (args, 1, 1, list (x));
-    [dummy,df] = leval (fun, args);
+    [dummy,df] = feval (fun, x, args{2:end});
   end
 end
Index: main/optim/inst/deriv.m
===================================================================
--- main/optim/inst/deriv.m	(revision 7325)
+++ main/optim/inst/deriv.m	(revision 7326)
@@ -1,3 +1,4 @@
+
 ## Copyright (C) 2000 Ben Sapp.  All rights reserved.
 ##
 ## This program is free software; you can redistribute it and/or modify it
@@ -28,17 +29,17 @@
   endif
   if(nargin >= 3)
     va_arg_cnt = 1;
-    h = nth (varargin, va_arg_cnt++);
+    h = varargin{va_arg_cnt++};
     if(!is_scalar(h))
       error("h must be a scalar.");
     endif
     if(nargin >= 4)
-      O = nth (varargin, va_arg_cnt++);
+      O = varargin{va_arg_cnt++};
       if((O != 2) && (O != 4))
 	error("Only order 2 or 4 is supported.\n");
       endif
       if(nargin >= 5)
-	N = nth (varargin, va_arg_cnt++);
+	N = varargin{va_arg_cnt++};
 	if((N > 4)||(N < 1))
 	  error("Only 1st,2nd,3rd or 4th order derivatives are acceptable.\n");
 	endif
@@ -83,3 +84,4 @@
       error("Only order 4 or 2 supported\n");
   endswitch
 endfunction
+
Index: main/optim/inst/test_fminunc_1.m
===================================================================
--- main/optim/inst/test_fminunc_1.m	(revision 7325)
+++ main/optim/inst/test_fminunc_1.m	(revision 7326)
@@ -91,7 +91,7 @@
 elseif verbose,  prn ("ok %i\n",cnt);
 end
 
-[xle2,vle2,nle2] = feval (method, "ff",list (x0,y0,1), ctl);
+[xle2,vle2,nle2] = feval (method, "ff",{x0,y0,1}, ctl);
 cnt++;
 				# nelder_mead_min is not very repeatable
 				# because of restarts from random positions
Index: main/optim/inst/minimize.m
===================================================================
--- main/optim/inst/minimize.m	(revision 7325)
+++ main/optim/inst/minimize.m	(revision 7326)
@@ -134,23 +134,7 @@
 		    "isz",  nan);
 
 if nargin == 3			# Accomodation to struct and list optional
-  va_arg_cnt = 1;				# args
-  tmp = nth (varargin, va_arg_cnt++);
-
-  if isstruct (tmp)
-    opls = list ();
-    for [v,k] = tmp		# Treat separately unary and binary opts
-      if findstr ([" ",k," "],op0)
-	opls = append (opls, k);
-      else
-	opls = append (opls, k, v);
-      end
-    end
-  elseif is_list (tmp)
-    opls = tmp;
-  else
-    opls = list (tmp);
-  end
+  opls = varargin{1};
 else
   opls = varargin;
 end
@@ -191,11 +175,7 @@
 				# f(), unless backend is specified, in which
 				# case I don't need to call f()
 if ! isnan (narg) && ! backend
-  if is_list (args)
-    if narg > length (args)
-      es = [es,sprintf("narg=%i > length(args)=%i\n",narg, length(args))];
-    end
-  elseif narg > 1
+  if narg > 1
     es = [es,sprintf("narg=%i, but a single argument was passed\n",narg)];
   end
 end
@@ -265,21 +245,21 @@
 if length (ws), warn (ws); end
 				# EOF More checks ##########################
 
-if     strcmp (method, "d2_min"), all_args = list (f, d2f, args);
-elseif strcmp (method, "bfgsmin"),all_args = list (f, args);
-else                              all_args = list (f, args);
+if     strcmp (method, "d2_min"), all_args = {f, d2f, args};
+elseif strcmp (method, "bfgsmin"),all_args = {f, args};
+else                              all_args = {f, args};
 end
 				# Eventually add ctls to argument list
-if op, all_args = append (all_args, list (ctls)); end
+if op, all_args{end+1} = {ctls}; end
 
+  method,
 if ! backend			# Call the backend ###################
   if strcmp (method, "d2_min"),
-    [x,v,nev,h] = leval (method, all_args);
+    [x,v,nev,h] = d2_min(all_args{:});
 				# Eventually return inverse of Hessian
-    if nargout > 3, vr_val_cnt = 1; varargout{vr_val_cnt++} = h; end 
+    if nargout > 3, varargout{1} = h; vr_val_cnt=2; end 
   elseif strcmp (method, "bfgsmin")
     nev = nan;
-    if is_list (args),tmp={};for i=1:length(args),tmp{i}=nth(args,i);end;args=tmp;end
     if !iscell(args), args = {args}; end
     if isnan (ftol), ftol = 1e-12; end # Use bfgsmin's defaults
     if isnan (utol), utol = 1e-6; end
@@ -287,7 +267,7 @@
     if isnan (maxev), maxev = inf; end
     [x, v, okcv] = bfgsmin (f, args, {maxev,verbose,1,narg},{ftol,utol,dtol});
   else
-    [x,v,nev] = leval (method, all_args);
+    [x,v,nev] = feval (method, all_args{:});
   end
 
 else				# Don't call backend, just return its name
------------------------------------------------------------------------------

_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to