annotate scripts/optimization/pqpnonneg.m @ 31551:fd29c7a50a78 stable

maint: use commas, semicolons consistently with Octave conventions. * makeValidName.m: Remove %!test and move BIST %!asserts to column 1. * base64decode.m, base64encode.m, which.m, logm.m, uniquetol.m, perms.m: Delete semicolon (';') at end of %!assert BIST. * lin2mu.m, interp2.m, interpn.m, lsqnonneg.m, pqpnonneg.m, uniquetol.m, betainc.m, normalize.m: Add semicolon (';') to end of assert statement within %!test BIST. * __memoize__.m, tar_is_bsd.m, publish.m: Add semicolon (';') to line with keyword "persistent". * stft.m: Use comma (',') after "case" keyword when code immediately follows. * gallery.m: Align commas used in case statements in massive switch block. Remove unnecessary parentheses around a numeric case argument. * ranks.m: Remove semicolon (';') from case statemnt argument.
author Rik <rik@octave.org>
date Sat, 26 Nov 2022 06:32:08 -0800
parents 10a813492497
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2008-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 ##
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 ## This file is part of Octave.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 ##
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 ##
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
27 ## @deftypefn {} {@var{x} =} pqpnonneg (@var{c}, @var{d})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
28 ## @deftypefnx {} {@var{x} =} pqpnonneg (@var{c}, @var{d}, @var{x0})
22760
c4d80b9d2898 maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents: 22755
diff changeset
29 ## @deftypefnx {} {@var{x} =} pqpnonneg (@var{c}, @var{d}, @var{x0}, @var{options})
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
30 ## @deftypefnx {} {[@var{x}, @var{minval}] =} pqpnonneg (@dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
31 ## @deftypefnx {} {[@var{x}, @var{minval}, @var{exitflag}] =} pqpnonneg (@dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
32 ## @deftypefnx {} {[@var{x}, @var{minval}, @var{exitflag}, @var{output}] =} pqpnonneg (@dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
33 ## @deftypefnx {} {[@var{x}, @var{minval}, @var{exitflag}, @var{output}, @var{lambda}] =} pqpnonneg (@dots{})
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
34 ##
31270
635ef1eb7dc3 doc: Improve docstring readability for pqpnonneg.m
Arun Giridhar <arungiridhar@gmail.com>
parents: 31268
diff changeset
35 ## Minimize @code{ (1/2 * @var{x}' * @var{c} * @var{x} + @var{d}' * @var{x}) }
635ef1eb7dc3 doc: Improve docstring readability for pqpnonneg.m
Arun Giridhar <arungiridhar@gmail.com>
parents: 31268
diff changeset
36 ## subject to @code{@var{x} >= 0}.
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
37 ##
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
38 ## @var{c} and @var{d} must be real matrices, and @var{c} must be symmetric and
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
39 ## positive definite.
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
40 ##
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
41 ## @var{x0} is an optional initial guess for the solution @var{x}.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 ##
22760
c4d80b9d2898 maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents: 22755
diff changeset
43 ## @var{options} is an options structure to change the behavior of the
28959
5394d688d456 doc: Use @code{} within alternate text for @xref,@pxref macros for better Info display.
Rik <rik@octave.org>
parents: 28942
diff changeset
44 ## algorithm (@pxref{XREFoptimset,,@code{optimset}}). @code{pqpnonneg}
5394d688d456 doc: Use @code{} within alternate text for @xref,@pxref macros for better Info display.
Rik <rik@octave.org>
parents: 28942
diff changeset
45 ## recognizes one option: @qcode{"MaxIter"}.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46 ##
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
47 ## Outputs:
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
48 ##
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
49 ## @table @var
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
50 ##
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
51 ## @item x
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
52 ## The solution matrix
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
53 ##
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 ## @item minval
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
55 ## The minimum attained model value,
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
56 ## @code{1/2*@var{xmin}'*@var{c}*@var{xmin} + @var{d}'*@var{xmin}}
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
57 ##
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 ## @item exitflag
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
59 ## An indicator of convergence. 0 indicates that the iteration count was
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
60 ## exceeded, and therefore convergence was not reached; >0 indicates that the
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
61 ## algorithm converged. (The algorithm is stable and will converge given
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
62 ## enough iterations.)
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
63 ##
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
64 ## @item output
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
65 ## A structure with two fields:
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
66 ##
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
67 ## @itemize @bullet
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24534
diff changeset
68 ## @item @qcode{"algorithm"}: The algorithm used (@nospell{@qcode{"nnls"}})
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
69 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 14366
diff changeset
70 ## @item @qcode{"iterations"}: The number of iterations taken.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
71 ## @end itemize
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
72 ##
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73 ## @item lambda
31286
10a813492497 maint: Use "nonzero" in docstrings and error messages.
Rik <rik@octave.org>
parents: 31283
diff changeset
74 ## Lagrange multipliers. If these are nonzero, the corresponding @var{x}
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
75 ## values should be zero, indicating the solution is pressed up against a
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
76 ## coordinate plane. The magnitude indicates how much the residual would
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
77 ## improve if the @code{@var{x} >= 0} constraints were relaxed in that
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
78 ## direction.
31266
e5e35410da90 doc: Documented undocumented outputs for lsqnonneg and pqpnonneg
Arun Giridhar <arungiridhar@gmail.com>
parents: 30564
diff changeset
79 ##
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
80 ## @end table
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
81 ## @seealso{lsqnonneg, qp, optimset}
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
82 ## @end deftypefn
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
83
13027
b9a89ca0fb75 prevent optimization functions from setting ans in workspace at startup
John W. Eaton <jwe@octave.org>
parents: 11588
diff changeset
84 ## PKG_ADD: ## Discard result to avoid polluting workspace with ans at startup.
b9a89ca0fb75 prevent optimization functions from setting ans in workspace at startup
John W. Eaton <jwe@octave.org>
parents: 11588
diff changeset
85 ## PKG_ADD: [~] = __all_opts__ ("pqpnonneg");
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
86
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
87 ## This is analogical to the lsqnonneg implementation, which is implemented
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
88 ## from Lawson and Hanson's 1973 algorithm on page 161 of Solving Least Squares
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
89 ## Problems. It shares the convergence guarantees.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
90
22769
9bd2ea5703e2 lsqnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22764
diff changeset
91 function [x, minval, exitflag, output, lambda] = pqpnonneg (c, d, x0 = [],
9bd2ea5703e2 lsqnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22764
diff changeset
92 options = struct ())
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
93
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
94 ## Special case: called to find default optimization options
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
95 if (nargin == 1 && ischar (c) && strcmp (c, "defaults"))
26138
804e18e3e320 Reenable query of optimization options (bugs #54952 and #55089).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25579
diff changeset
96 x = struct ("MaxIter", 1e5);
17312
088d014a7fe2 Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents: 17281
diff changeset
97 return;
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
98 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
99
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27923
diff changeset
100 if (nargin < 2)
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
101 print_usage ();
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
102 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
104 if (! (isnumeric (c) && ismatrix (c)) || ! (isnumeric (d) && ismatrix (d)))
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
105 error ("pqpnonneg: C and D must be numeric matrices");
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
106 endif
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
107 if (! issquare (c))
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
108 error ("pqpnonneg: C must be a square matrix");
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
109 endif
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
110
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
111 if (! isstruct (options))
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
112 error ("pqpnonneg: OPTIONS must be a struct");
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
113 endif
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
114
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
115 ## Lawson-Hanson Step 1 (LH1): initialize the variables.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
116 n = columns (c);
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
117 if (isempty (x0))
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
118 ## Initial guess is all zeros.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
119 x = zeros (n, 1);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
120 else
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
121 ## ensure nonnegative guess.
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
122 x = max (x0, 0);
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
123 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
125 max_iter = optimget (options, "MaxIter", 1e5);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127 ## Initialize P, according to zero pattern of x.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 p = find (x > 0).';
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129 ## Initialize the Cholesky factorization.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130 r = chol (c(p, p));
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 usechol = true;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
133 iter = 0;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135 ## LH3: test for completion.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
136 while (iter < max_iter)
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
137 while (iter < max_iter)
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20165
diff changeset
138 iter += 1;
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
140 ## LH6: compute the positive matrix and find the min norm solution
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
141 ## of the positive problem.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
142 if (usechol)
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
143 xtmp = -(r \ (r' \ d(p)));
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
144 else
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
145 xtmp = -(c(p,p) \ d(p));
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
146 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
147 idx = find (xtmp < 0);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
148
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
149 if (isempty (idx))
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
150 ## LH7: tmp solution found, iterate.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
151 x(:) = 0;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
152 x(p) = xtmp;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
153 break;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
154 else
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
155 ## LH8, LH9: find the scaling factor.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
156 pidx = p(idx);
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
157 sf = x(pidx) ./ (x(pidx) - xtmp(idx));
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
158 alpha = min (sf);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
159 ## LH10: adjust X.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
160 xx = zeros (n, 1);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
161 xx(p) = xtmp;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
162 x += alpha*(xx - x);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
163 ## LH11: move from P to Z all X == 0.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
164 ## This corresponds to those indices where minimum of sf is attained.
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
165 idx = idx(sf == alpha);
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
166 p(idx) = [];
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
167 if (usechol)
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
168 ## update the Cholesky factorization.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
169 r = choldelete (r, idx);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
170 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
171 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
172 endwhile
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
173
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
174 ## compute the gradient.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
175 w = -(d + c*x);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
176 w(p) = [];
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
177 if (! any (w > 0))
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
178 if (usechol)
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
179 ## verify the solution achieved using qr updating.
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
180 ## In the best case, this should only take a single step.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
181 usechol = false;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
182 continue;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
183 else
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
184 ## we're finished.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
185 break;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
186 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
187 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
188
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
189 ## find the maximum gradient.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
190 idx = find (w == max (w));
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
191 if (numel (idx) > 1)
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
192 warning ("pqpnonneg:nonunique",
11588
d5bd2766c640 style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
193 "a non-unique solution may be returned due to equal gradients");
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
194 idx = idx(1);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
195 endif
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21178
diff changeset
196 ## move the index from Z to P. Keep P sorted.
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
197 z = [1:n]; z(p) = [];
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
198 zidx = z(idx);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
199 jdx = 1 + lookup (p, zidx);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
200 p = [p(1:jdx-1), zidx, p(jdx:end)];
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
201 if (usechol)
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
202 ## insert the column into the Cholesky factorization.
10200
7c1b1c084af1 handle cholesky update failure in pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents: 9635
diff changeset
203 [r, bad] = cholinsert (r, jdx, c(p,zidx));
7c1b1c084af1 handle cholesky update failure in pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents: 9635
diff changeset
204 if (bad)
7c1b1c084af1 handle cholesky update failure in pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents: 9635
diff changeset
205 ## If the insertion failed, we switch off updates and go on.
7c1b1c084af1 handle cholesky update failure in pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents: 9635
diff changeset
206 usechol = false;
7c1b1c084af1 handle cholesky update failure in pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents: 9635
diff changeset
207 endif
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
208 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
209
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
210 endwhile
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
211 ## LH12: complete.
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
212
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
213 ## Generate the additional output arguments.
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
214 if (isargout (2))
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
215 minval = 1/2*(x'*c*x) + d'*x;
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
216 endif
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
217 if (isargout (3))
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
218 if (iter >= max_iter)
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
219 exitflag = 0;
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
220 else
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
221 exitflag = iter;
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
222 endif
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
223 endif
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
224 if (isargout (4))
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
225 output = struct ("algorithm", "nnls-pqp", "iterations", iter);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
226 endif
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
227 if (isargout (5))
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
228 lambda = zeros (size (x));
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
229 lambda (setdiff (1:numel(x), p)) = w;
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
230 endif
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
231
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
232 endfunction
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
233
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
234
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
235 %!test
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
236 %! C = [5 2;2 2];
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
237 %! d = [3; -1];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
238 %! assert (pqpnonneg (C, d), [0;0.5], 100*eps);
9635
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
239
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
240 ## Test equivalence of lsq and pqp
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
241 %!test
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
242 %! C = rand (20, 10);
36d885c4a1ac implement pqpnonneg
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243 %! d = rand (20, 1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
244 %! assert (pqpnonneg (C'*C, -C'*d), lsqnonneg (C, d), 100*eps);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
245
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
246 ## Test Lagrange multiplier duality: lambda .* x == 0
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
247 %!test
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
248 %! [x, resid, ~, ~, lambda] = pqpnonneg ([3 2; 2 2], [6; 5]);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
249 %! assert (x, [0 0]', eps);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
250 %! assert (resid, 0, eps);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
251 %! assert (lambda, [-6 -5]', eps);
31551
fd29c7a50a78 maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents: 31286
diff changeset
252 %! assert (x .* lambda, [0 0]');
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
253
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
254 %!test
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
255 %! [x, resid, ~, ~, lambda] = pqpnonneg ([3 2; 2 2], [6; -5]);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
256 %! assert (x, [0 2.5]', eps);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
257 %! assert (resid, -6.25, eps);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
258 %! assert (lambda, [-11 0]', eps);
31551
fd29c7a50a78 maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents: 31286
diff changeset
259 %! assert (x .* lambda, [0 0]');
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
260
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
261 %!test
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
262 %! [x, resid, ~, ~, lambda] = pqpnonneg ([3 2; 2 2], [-6; 5]);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
263 %! assert (x, [2 0]', eps);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
264 %! assert (resid, -6, eps);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
265 %! assert (lambda, [0 -9]', eps);
31551
fd29c7a50a78 maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents: 31286
diff changeset
266 %! assert (x .* lambda, [0 0]');
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
267
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
268 %!test
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
269 %! [x, resid, ~, ~, lambda] = pqpnonneg ([3 2; 2 2], [-6; -5]);
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
270 %! assert (x, [1 1.5]', 10*eps);
31283
b902f78ecf66 pqpnonneg.m: increase tolerance on BIST (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31270
diff changeset
271 %! assert (resid, -6.75, 10*eps);
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
272 %! assert (lambda, [0 0]', eps);
31551
fd29c7a50a78 maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents: 31286
diff changeset
273 %! assert (x .* lambda, [0 0]');
31268
44a68ac1a22f Fix incorrect lambda outputs for lsqnonneg and pqpnonneg (bug #63178)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31266
diff changeset
274
28942
fc4bb4bd1d5e maint: Use '##' as lead-in for full-line comments.
Rik <rik@octave.org>
parents: 28896
diff changeset
275 ## Test input validation
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28789
diff changeset
276 %!error <Invalid call> pqpnonneg ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28789
diff changeset
277 %!error <Invalid call> pqpnonneg (1)
22764
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
278 %!error <C .* must be numeric matrices> pqpnonneg ({1},2)
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
279 %!error <C .* must be numeric matrices> pqpnonneg (ones (2,2,2),2)
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
280 %!error <D must be numeric matrices> pqpnonneg (1,{2})
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
281 %!error <D must be numeric matrices> pqpnonneg (1, ones (2,2,2))
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
282 %!error <C must be a square matrix> pqpnonneg ([1 2], 2)
d261dcd73dcf pqpnonneg.m: Overhaul function.
Rik <rik@octave.org>
parents: 22760
diff changeset
283 %!error <OPTIONS must be a struct> pqpnonneg (1, 2, [], 3)