Søren Hauberg wrote:
> man, 24 05 2010 kl. 22:16 +0200, skrev Alois Schlögl:
>> I've committed the changes already in r7326, so others (e.g. Michael)
>> can see and test against them. The diff is attached.
>
> These changes look good to me; thanks for doing this.
>
> A few minor questions:
>
>> -while niter++ <= maxout && nev(1) < maxev
>> +while niter <= maxout
>> + niter += 1;
>> + if nev(1) < maxev, break; end;
>
> I don't understand this change. I guess you moved the ++ operation to
> help 'oct2mat' (which is fine by me),
Good, thanks.
but why didn't you just write
>
> while (niter <= maxout && nev (1) < maxev)
> niter ++;
When the condition is false, niter is not incremented anymore. So, niter
might be off by 1 when the while loop terminates.
niter is checked after the loop has terminated, and the loop can also
terminate by some break statements. So, there might be a slight chance
that this difference is relevant.
>
> ?
>
>> - c = 1 + sum ((x-y)(:)'*z*((x-y)(:)));
>> + c = 1 + sum (vec(x-y)'*z*(vec(x-y)));
>
> What is the purpose of this (and similar) change?
Its again an issue with oct2mat, which can not deal well with (x-y)(:),
especially if these are used within more complicated constructs. Using
vec() avoids this problem.
>
>> 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};
>
> I am most certainly missing the something here, but this change just
> looks odd to me. Can all of the above really be reduced to one line of
> code?
The line of thought was that append, is_list and list are all
list-specific commands. Since lists are not supported anymore in v3.4,
this would be obsolete. Now, I see that this was a short-sighted view.
This part should convert various types of input arguments into cell
arrays. Thanks for pointing this out.
I found some other issues, that were not properly addressed in the
list->cell conversion. The changes are summarized in the patch below, I
committed them already.
Index: line_min.m
===================================================================
--- line_min.m (revision 7326)
+++ line_min.m (working copy)
@@ -51,9 +51,12 @@
a = 0;
# was 1e-4
while (abs (velocity) > 0.000001)
- 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}}{:});
+ arglist = {args{1:narg-1}, x+a*dx, args{narg+1:end}};
+ fx = feval (f,arglist{:});
+ arglist = {args{1:narg-1}, x+(a+h)*dx, args{narg+1:end}};
+ fxph = feval (f,arglist{:});
+ arglist = {args{1:narg-1}, x+(a-h)*dx, args{narg+1:end}};
+ fxmh = feval (f,arglist{:});
velocity = (fxph - fxmh)/(2*h);
acceleration = (fxph - 2*fx + fxmh)/(h^2);
Index: fminunc_compat.m
===================================================================
--- fminunc_compat.m (revision 7326)
+++ fminunc_compat.m (working copy)
@@ -119,7 +119,7 @@
if findstr ([" ",k," "], unary_opt)
opml{end+1} = {k};
else
- opml{end+1} = {k,v};
+ opml{end+[1,2]} = {k,v}; # append k and v
end
end
# Return only options to minimize() ##
Index: minimize.m
===================================================================
--- minimize.m (revision 7326)
+++ minimize.m (working copy)
@@ -134,7 +134,22 @@
"isz", nan);
if nargin == 3 # Accomodation to struct and list
optional
- opls = varargin{1};
+ tmp = varargin{1};
+
+ if isstruct (tmp)
+ opls = {};
+ for [v,k] = tmp # Treat separately unary and binary opts
+ if findstr ([" ",k," "],op0)
+ opls {end+1} = k;
+ else
+ opls {end+[1:2]} = {k, v};
+ end
+ end
+ elseif iscell (tmp)
+ opls = tmp;
+ else
+ opls = {tmp};
+ end
else
opls = varargin;
end
Alois
------------------------------------------------------------------------------
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev