Originally posted by: ChristophHeidelberg
Similar to this question (https://www.ibm.com/developerworks/community/forums/html/topic?id=3fdbaa8a-f76b-49f1-a41b-f2df4e9b2f33&ps=100 ) I would like to do Least Squared optimisation (with a quadratic constraint in my case). In each iteration but the first I get a negative value for the objective function.
Can some one tell me why that is? I assume I've done something wrong in setting up my problem, but surely the objective function should not be negative in a least squares problem.
Here is the code.
n = 26625; % Or try smaller values n=100, dim=5, dictsize=20
dim = 31;
dictsize = 500;
A = rand(dictsize,n);
D = rand(dim, dictsize);
D = bsxfun(@rdivide, D, sqrt(sum(D .^2))); % Normalise D.
X = D * A;
d = D';
d = d(:)';
x = X';
x = x(:)';
A_aug = [];
for i=1:dim
A_aug = blkdiag(sparse(A), A_aug);
end
disp(norm(x - d*A_aug, 2));
% Setup constraints
% Q = sparse(eye(dim*dictsize));
% r = 1* dictsize;
% l = zeros(dim*dictsize,1);
Q = cell(1, dictsize);
r = zeros(1, dictsize);
l = zeros(dim*dictsize, dictsize);
for i=1:dictsize
r(i) = 1;
Q{i} = sparse(zeros(dim*dictsize));
il = (i-1)*dim + 1;
iu = i*dim;
Q{i}((il:iu),(il:iu)) = sparse(eye(dim));
l(:,i) = zeros(dim* dictsize, 1);
end
options = cplexoptimset('MaxIter', 30, 'Display', 'on');
% Optimise
tic;
[d_est, resnorm, ~, exitflag, output] = cplexlsqqcp(A_aug',x',zeros(1, dim*dictsize),ones(1,1),...
zeros(1,dim*dictsize),zeros(1,1),...
l,Q, r,...
[], [], [],...
options);
toc;
if exitflag > 0
fprintf('Valid solution found\n');
fprintf('Time taken %f, %d\n', output.time, output.iterations);
fprintf('Error: %f\n', resnorm);
end
disp(norm(d - d_est') / norm(d));
Dest = reshape(d_est, [dim dictsize]);
The code works but prints negative values for the objective function...
#CPLEXOptimizers#DecisionOptimization