# HG changeset patch # User Jaroslav Hajek
# Date 1225436774 -3600 # Node ID ae6cb5e2d988810b062d65a68d6055e5b3054501 # Parent e81bb4c503b52790915fd70c8427e929759d0474 modify optimset & implement optimget diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -0,0 +1,8 @@ +2008-10-31 Jaroslav Hajek + + * optimization/optimset.m: Don't include empty options in option + structure. + * optimization/optimget.m: New function file. + * optimization/Makefile.in: Add it. + * optimization/lsqnonneg.m: Query options using optimget. + diff --git a/scripts/optimization/Makefile.in b/scripts/optimization/Makefile.in --- a/scripts/optimization/Makefile.in +++ b/scripts/optimization/Makefile.in @@ -38,6 +38,7 @@ glpkmex.m \ lsqnonneg.m \ optimset.m \ + optimget.m \ qp.m \ sqp.m diff --git a/scripts/optimization/lsqnonneg.m b/scripts/optimization/lsqnonneg.m --- a/scripts/optimization/lsqnonneg.m +++ b/scripts/optimization/lsqnonneg.m @@ -67,10 +67,7 @@ x = zeros (columns (c), 1); endif - if (isempty (options)) - ## FIXME: what are the correct defaults? - options = optimset ("maxiter", 1e5, "tolx", 1e-8); - endif + MaxIter = optimget (options, "MaxIter", 1e5); ## Initialize the values. p = []; @@ -80,7 +77,7 @@ iter = 0; ## LH3: test for completion. - while (! isempty (z) && any (w(z) > 0) && iter < options.MaxIter) + while (! isempty (z) && any (w(z) > 0) && iter < MaxIter) ## LH4: find the maximum gradient. idx = find (w == max (w)); if (numel (idx) > 1) @@ -93,7 +90,7 @@ p(end+1) = idx; newx = false; - while (! newx && iter < options.MaxIter) + while (! newx && iter < MaxIter) iter++; ## LH6: compute the positive matrix and find the min norm solution @@ -132,7 +129,7 @@ residual = d-C*x; endif exitflag = iter; - if (nargout > 3 && iter >= options.MaxIter) + if (nargout > 3 && iter >= MaxIter) exitflag = 0; endif if (nargout > 4) diff --git a/scripts/optimization/optimget.m b/scripts/optimization/optimget.m new file mode 100644 --- /dev/null +++ b/scripts/optimization/optimget.m @@ -0,0 +1,39 @@ +## Copyright (C) 2008 Jaroslav Hajek +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +##