LSQNONNEG function with large amount of data
Show older comments
Hi,
I'm trying to run the lsqnonneg function(finding least squares solution with the constraint of non-negativity).
I'm having problems when the data is huge - I'm getting this error message : "Exiting: Iteration count is exceeded, exiting LSQNONNEG.
Try raising the tolerance (OPTIONS.TolX)."
Also, the result returned is an intermediate solution, which is not non-negative and therefore not a valid solution.
I'm guessing that maybe the algorithm failes to find a solution on such huge amounts of data(at some point the positive set array is all zeros, and that is when the algorithm gets "stuck"), the question is if there is anything I can do other than reducing the amount of data.
I have attached a .mat file with the parameters C and d(where C is the matrix and the first param and d is second param).
Thanks in advance.
1 Comment
Borong Liu
on 3 Jan 2023
Hi,
I have the same problem, have you fixed it?
Thanks in advance.
Answers (1)
John D'Errico
on 3 Jan 2023
Edited: John D'Errico
on 3 Jan 2023
No answer was made, so too late for @Neil Cohen. (Sorry about that. But @Borong Liu might gain.) Since there is still interest, I'll show one option to solve it.
whos C d
Name Size Bytes Class Attributes
C 257600x5 10304000 double
d 257600x1 2060800 double
So it is not too huge of a problem. But lsqnonneg did have a problem.
lsqnonneg(C,d)
Exiting: Iteration count is exceeded, exiting LSQNONNEG.
Try raising the tolerance (OPTIONS.TolX).
ans =
-0.000368354710649102
0.227251353522795
0
0
0
Even so, I woud have thought lsqnonneg would handle this. So the obvious solution is to try lsqlin.
lsqlin(C,d,[],[],[],[],zeros(1,5))
Minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
<stopping criteria details>
ans =
4.66053409046511e-23
0.201099498918889
0.124298333566924
0.760555144151411
0.215357073925574
No problem. However, this still begs the question as to how to get lsqnonneg to work. Perhaps I'll just take the advice it gave, since there are only two options that lsqnonneg uses anyway.
opts = optimset('lsqnonneg');
opts.TolX = 1e-12;
lsqnonneg(C,d,opts)
ans =
0
0.201099498918889
0.124298333566995
0.760555144149044
0.215357073938012
Which appears to be fundamentally the same solution that lsqlin returns.
5 Comments
Arnab Paul
on 6 Sep 2023
Edited: Arnab Paul
on 6 Sep 2023
Hi John
I have different problem
I have two matrix A_matrix and b
The dimension is
A_matrix = 301x16
b = 301x 255651.
To use b as vector I am using this code
x = zeros(size(A_matrix, 2), size(b, 2));
% Perform Non-Negative Least Squares
options = optimset('TolX', 1e-12); %
for i = 1:size(b, 2)
x(:, i) = lsqnonneg(A_matrix, b(:, i), options);
end
now x has the dimension of 16x255651
b has NaN values in it as well as positive values and A_matrix has all the positive values.
The output x coming 0 in the matrix. Kindly help me with the problem
Torsten
on 6 Sep 2023
Skip the columns of b with NaN values. Or what was your question ?
Arnab Paul
on 11 Oct 2023
Edited: Arnab Paul
on 11 Oct 2023
The output x has zero in the last row. 16 rows are the bands of satellite and the columns are pixels values. How not to get 0 values in the last row while using lsqnonneg?
I have converted NaNs to 0s.
John D'Errico
on 11 Oct 2023
Edited: John D'Errico
on 11 Oct 2023
That all elements in the last row are zero merely means that that component is always best chosen as zero, since it really wants to be negative. What function are you using? LSQNONNEG. If a given element strongly needs to be negative, then lsqnonneg effectively uses zero instead.
Just wanting a different result is not sufficient.
Arnab Paul
on 11 Oct 2023
yes I am using lsqnonneg. Is their any way I can moify the Tolx or apply the different "Algorithm". So that I can get values instead of zero?
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!