Mercurial > hg > octave-lyh
comparison scripts/optimization/lsqnonneg.m @ 14787:acb09716fc94
lsqnonneg have tolerance option for convergence (bug #33347)
author | Axel Mathéi <axel.mathei@gmail.com> |
---|---|
date | Thu, 21 Jun 2012 12:15:38 +0200 |
parents | b76f0740940e |
children | 5d3a684236b0 |
comparison
equal
deleted
inserted
replaced
14786:e70a0c9cada6 | 14787:acb09716fc94 |
---|---|
19 ## <http://www.gnu.org/licenses/>. | 19 ## <http://www.gnu.org/licenses/>. |
20 | 20 |
21 ## -*- texinfo -*- | 21 ## -*- texinfo -*- |
22 ## @deftypefn {Function File} {@var{x} =} lsqnonneg (@var{c}, @var{d}) | 22 ## @deftypefn {Function File} {@var{x} =} lsqnonneg (@var{c}, @var{d}) |
23 ## @deftypefnx {Function File} {@var{x} =} lsqnonneg (@var{c}, @var{d}, @var{x0}) | 23 ## @deftypefnx {Function File} {@var{x} =} lsqnonneg (@var{c}, @var{d}, @var{x0}) |
24 ## @deftypefnx {Function File} {@var{x} =} lsqnonneg (@var{c}, @var{d}, @var{x0}, @var{options}) | |
24 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}] =} lsqnonneg (@dots{}) | 25 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}] =} lsqnonneg (@dots{}) |
25 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}] =} lsqnonneg (@dots{}) | 26 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}] =} lsqnonneg (@dots{}) |
26 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}, @var{exitflag}] =} lsqnonneg (@dots{}) | 27 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}, @var{exitflag}] =} lsqnonneg (@dots{}) |
27 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}, @var{exitflag}, @var{output}] =} lsqnonneg (@dots{}) | 28 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}, @var{exitflag}, @var{output}] =} lsqnonneg (@dots{}) |
28 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}, @var{exitflag}, @var{output}, @var{lambda}] =} lsqnonneg (@dots{}) | 29 ## @deftypefnx {Function File} {[@var{x}, @var{resnorm}, @var{residual}, @var{exitflag}, @var{output}, @var{lambda}] =} lsqnonneg (@dots{}) |
29 ## Minimize @code{norm (@var{c}*@var{x} - d)} subject to | 30 ## Minimize @code{norm (@var{c}*@var{x} - d)} subject to |
30 ## @code{@var{x} >= 0}. @var{c} and @var{d} must be real. @var{x0} is an | 31 ## @code{@var{x} >= 0}. @var{c} and @var{d} must be real. @var{x0} is an |
31 ## optional initial guess for @var{x}. | 32 ## optional initial guess for @var{x}. |
33 ## Currently, @code{lsqnonneg} | |
34 ## recognizes these options: @code{"MaxIter"}, @code{"TolX"}. | |
35 ## For a description of these options, see @ref{doc-optimset,,optimset}. | |
32 ## | 36 ## |
33 ## Outputs: | 37 ## Outputs: |
34 ## | 38 ## |
35 ## @itemize @bullet | 39 ## @itemize @bullet |
36 ## @item resnorm | 40 ## @item resnorm |
145 endwhile | 149 endwhile |
146 | 150 |
147 ## compute the gradient. | 151 ## compute the gradient. |
148 w = c'*(d - c*x); | 152 w = c'*(d - c*x); |
149 w(p) = []; | 153 w(p) = []; |
150 if (! any (w > 0)) | 154 tolx = optimget (options, "TolX", 10*eps*norm (c, 1)*length (c)); |
155 if (! any (w > tolx)) | |
151 if (useqr) | 156 if (useqr) |
152 ## verify the solution achieved using qr updating. | 157 ## verify the solution achieved using qr updating. |
153 ## in the best case, this should only take a single step. | 158 ## in the best case, this should only take a single step. |
154 useqr = false; | 159 useqr = false; |
155 continue; | 160 continue; |