From: Steven Lord on

"Walter Roberson" <roberson(a)hushmail.com> wrote in message
news:hsa5r2$knr$1(a)canopus.cc.umanitoba.ca...
> Gene wrote:

*snip*

> I have checked the documentation for lsqnonneg, and I have checked the
> documentation describing the use of tilde,
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#br67dkp-1
>
> and I do not see anything in either that would indicate general support
> for using ~ to indicate an unknown value when making a call to a function.
> ~ is supported at function *definition* to indicate an argument that the
> caller will provide an argument in that position that should be ignored.

The tilde operator can be used to indicate an argument should be ignored in
two cases.

1) In the _declaration_ of the function, a tilde on the RIGHT side of the
equals sign (as an input) indicates that the function will not use the input
argument you provide when you call the function.
2) In the _function call_, a tilde on the LEFT side of the equals sign (as
an output) indicates that the corresponding output should not be assigned to
a variable in the calling workspace.

You can't specify a tilde on the LEFT side of the declaration or the RIGHT
side of the function call (well, not on its own. You can call a function
with something like ~x as an input if you want, but in that situation it
doesn't mean "ignore this" but means "logical not".)

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Gene on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hsa5r2$knr$1(a)canopus.cc.umanitoba.ca>...
> Gene wrote:
> > [X, RESNORM, RESIDUAL, EXITFLAG] = LSQNONNEG(A, b, X0, OPTIONS)
> >
> > use OPTIMSET to specify the MaxIter field in the OPTIONS structure. With
> > recent versions of Matlab you can replace X0 with ~ (if you don't have a
> > reasonable initial estimate).
>
> The documentation,
> http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/lsqnonneg.html
> appears to indicate that in order to supply X0, you must call lsqnonneg
> passing it a "problem", where a "problem" is a structure with various fields,
> including X0 and options . There does not appear to be any way to create a
> "problem" without an X0. If, however, one were simply to omit X0 from the call
> shown above, the call with just A, b, and OPTIONS *would* be a supported syntax.
>
>
> I have checked the documentation for lsqnonneg, and I have checked the
> documentation describing the use of tilde,
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/bresuxt-1.html#br67dkp-1
>
> and I do not see anything in either that would indicate general support for
> using ~ to indicate an unknown value when making a call to a function. ~ is
> supported at function *definition* to indicate an argument that the caller
> will provide an argument in that position that should be ignored.
>
> Gene, would you be able to provide a link to documentation of using ~ the way
> you describe?

Walter & Adnan:

I think I must request forgiveness for going (less than ? ) half-cocked.

On the use of tilde (~), I recalled a blog from L. Shure:
http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/
I have not tested this in the lsqnonneg application. Moreover, the documentation states that one can simply 'send' an empty array as a place-holder.

On the specification of MaxIter, I assumed there was an underlying 'active-set' method in which the algorithm has a current estimate for which components of x = 0 (the active set). Such an algorithm would then 'solve' an equality constrained problem (in this case a 'quadratic programming problem'. The resulting Lagrange multipliers would be tested for KKT conditions, while the non-zero components of 'x' would tested for sign and the active-set might then be 'adjusted'. This class of algorithms would have a clear major iteration step.

I shall put the Lawson and Hanson reference on my 'to read' list.

Mea Culpa

gene
From: Adnan Abdulally on
Gene and others,

Thanks for the help so far. Ive been going through the parallel toolbox manual and i still cannot find a solution to this problem. I figured this would have been a pretty common problem amongst people using the toolbox, but i guess i was wrong.

Other than using optimset (which doesn't work for MaxIter) i thought of actually mexing the fortran code where i can probably set a maximum iteration value myself, but that just seems very convoluted. Plus, i can foresee this problem occurring again in the future, so it would be good if i figure this out for reference.

So here are my thoughts on the matter so far. I am also very new to the parallel toolbox, so i might say something wrong or that just doesnt work.

What if i:

1. have a worker that has time counters for each worker. This worker has a while loop that runs for the duration of the program.

2.Every time a worker finishes, the time counter resets to the current time. If the time exceeds, lets say, 500 seconds, it sends a flag out to kill the workers process.

3. the workers process is killed, and the worker starts the new iteration.

I will try to come up with proper code/pseudo code for this, but if anyone has inputs, please share them.

Thanks
From: Gene on
Adnan:
At the risk of further embarrassment, I'll paste in an 'alternative lsqnonneg' code. This seems to implement the algorithm as in the Lawson & Hanson, except that they 'solve' using the normal equations where we use Matlab's left-divide. The current code allows a user-specified it_max. I have not (yet) looked into the implementation provide in TMW's optimization toolbox.

For further correspondence, please emai me as
ecliff at vt/edu (making the obvious changes).

Have fun

gene

function [ x, res_norm, eJ, flag, lambda ] = my_lsqnoneg( A, b, it_max )
%Seek a nonnegative vector x to minimize \| Ax - b \|^2

% We implement an active set strategy

%% Initialization
[nb, nx] = size(A);
if length(b) ~= nb
error('A and b don''t have the same numer of rows')
end

if nargin < 3; it_max = 10*nx; end; % replace with some heuristic

Full = 1:nx;
xzero = zeros(nx, 1);

I_act = []; % indices for the initial active set
% e_min = inf; % a min-norm, feasible point can be stored by
% un-commenting this line and lines 39 - 42.

iter = 0;

% Begin main loop
while iter < it_max
iter = iter + 1;

%% least-squares solution using available variables
J = setdiff(Full, I_act);
xJ = A(:,J)\b;

%% test feasibility

Iv = find(xJ < 0); %#ok
if isempty(Iv)

%% compute the residual
eJ = A(:,J)*xJ - b;
x = xzero; x(J) = xJ; % full x array (with zeros)

% if norm(eJ) < e_min
% e_min = eJ;
% x_best= x;
% end % e_min

%% Compute KKT multipliers
lambda = eJ(:)'*A(:, I_act);
Jv = find(lambda < 0); %#ok
if isempty(Jv)

break

else
%% Find worst KKT violator and remove constraint from the active set
[~, Jv_worst] = min(lambda);
I_act = setdiff(I_act, I_act(Jv_worst));
end % KKT check

else

%% Find worst constraint violator and augment the active set
[~, Iv_worst] = min(xJ);
I_act = union(I_act, J(Iv_worst));

end % feasibility check

end % while

res_norm = norm(eJ);
flag = (iter < it_max);
end % function