From: Merel Newman on 3 Jul 2010 07:37 I'm trying to solve a nonnegative least-squares constraint problem using lsqnonneg() - how can I add constrains on lsqnonneg()'s solution ? for example - I need all the elements of the [x] vector returned as a solution to sum up to 1 ...how can I do that ? Thank you.
From: John D'Errico on 3 Jul 2010 09:29 "Merel Newman" <electrical_beem_666(a)hotmail.com> wrote in message <i0n7d0$npf$1(a)fred.mathworks.com>... > I'm trying to solve a nonnegative least-squares constraint problem using lsqnonneg() - how can I add constrains on lsqnonneg()'s solution ? > for example - I need all the elements of the [x] vector returned as a solution to sum up to 1 ...how can I do that ? > > Thank you. lsqlin will solve this, from the optimization toolbox. Ask again if you do not have access to that toolbox. The simple equality constraint you show can be achieved in other ways. (But lsqlin is simplest.) HTH, John
From: Merel Newman on 3 Jul 2010 17:19 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i0ndv0$mfu$1(a)fred.mathworks.com>... > "Merel Newman" <electrical_beem_666(a)hotmail.com> wrote in message <i0n7d0$npf$1(a)fred.mathworks.com>... > > I'm trying to solve a nonnegative least-squares constraint problem using lsqnonneg() - how can I add constrains on lsqnonneg()'s solution ? > > for example - I need all the elements of the [x] vector returned as a solution to sum up to 1 ...how can I do that ? > > > > Thank you. > > lsqlin will solve this, from the optimization toolbox. > > Ask again if you do not have access to that toolbox. > The simple equality constraint you show can be > achieved in other ways. (But lsqlin is simplest.) > > HTH, > John Thank you for your reply John, I've tried using lsqlin but didn't manage to get the right solution, this is what i did : the problem is : r = M*a subject to sum(a) = 1 and all elements of a >= 0 i used the following syntax : lb = zeros(5,1); ub = ones(5,1); [m,n] =size(M); [x,resnorm,residual,exitflag,output,lambda] = lsqlin(M,r,-eye(n,n),zeros(n,1),[],[],lb,ub) however the solution (x) doesn't sum up to 1 : exitflag = 1 output = iterations: 4 algorithm: [1x24 char] firstorderopt: [] cgiterations: [] message: [1x24 char] lambda = lower: [5x1 double] upper: [5x1 double] eqlin: [0x1 double] ineqlin: [5x1 double] sum(x) = 0.7956 any help would be appreciated. thanks, Merel.
From: John D'Errico on 3 Jul 2010 21:51 "Merel Newman" <electrical_beem_666(a)hotmail.com> wrote in message <i0o9gc$7f0$1(a)fred.mathworks.com>... > "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i0ndv0$mfu$1(a)fred.mathworks.com>... > > "Merel Newman" <electrical_beem_666(a)hotmail.com> wrote in message <i0n7d0$npf$1(a)fred.mathworks.com>... > > > I'm trying to solve a nonnegative least-squares constraint problem using lsqnonneg() - how can I add constrains on lsqnonneg()'s solution ? > > > for example - I need all the elements of the [x] vector returned as a solution to sum up to 1 ...how can I do that ? > > > > > > Thank you. > > > > lsqlin will solve this, from the optimization toolbox. > > > > Ask again if you do not have access to that toolbox. > > The simple equality constraint you show can be > > achieved in other ways. (But lsqlin is simplest.) > > > > HTH, > > John > > > Thank you for your reply John, I've tried using lsqlin but didn't manage to get the right solution, this is what i did : > the problem is : r = M*a > subject to sum(a) = 1 and all elements of a >= 0 > i used the following syntax : > > lb = zeros(5,1); > ub = ones(5,1); > [m,n] =size(M); > [x,resnorm,residual,exitflag,output,lambda] = lsqlin(M,r,-eye(n,n),zeros(n,1),[],[],lb,ub) > > however the solution (x) doesn't sum up to 1 : Yes, but that does not do what you want. What does it do? The first two args form the least squares problem min(norm(M*a - r)) This part is reasonable. Setting the lower bounds (lb) to be zeros(5,1) is also fine. However, there is no reason to set an upper bound on the parameters. If you know they are all positive, and the sum is 1, then can any of them exceed 1? Next, what is the purpose of the 3rd and 4th arguments? All they do are form a set of INEQUALITY constraints on the parameters, forcing them to be positive numbers. However, you already did that with the lower bounds! So these arguments are redundant. Finally, where have you tried to put in a sum constraint? What is the sum of the elements of a? Can you form the sum using a dot product? Yes. ones(1,5)*a == 1 is an equality constraint that yields the sum of your elements. So now, put it into a call to lsqlin. This is all you need. a = lsqlin(M,r,[],[],ones(1,5),1,lb); HTh, John
From: Merel Newman on 5 Jul 2010 12:23 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i0ope7$t3n$1(a)fred.mathworks.com>... > "Merel Newman" <electrical_beem_666(a)hotmail.com> wrote in message <i0o9gc$7f0$1(a)fred.mathworks.com>... > > "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i0ndv0$mfu$1(a)fred.mathworks.com>... > > > "Merel Newman" <electrical_beem_666(a)hotmail.com> wrote in message <i0n7d0$npf$1(a)fred.mathworks.com>... > > > > I'm trying to solve a nonnegative least-squares constraint problem using lsqnonneg() - how can I add constrains on lsqnonneg()'s solution ? > > > > for example - I need all the elements of the [x] vector returned as a solution to sum up to 1 ...how can I do that ? > > > > > > > > Thank you. > > > > > > lsqlin will solve this, from the optimization toolbox. > > > > > > Ask again if you do not have access to that toolbox. > > > The simple equality constraint you show can be > > > achieved in other ways. (But lsqlin is simplest.) > > > > > > HTH, > > > John > > > > > > Thank you for your reply John, I've tried using lsqlin but didn't manage to get the right solution, this is what i did : > > the problem is : r = M*a > > subject to sum(a) = 1 and all elements of a >= 0 > > i used the following syntax : > > > > lb = zeros(5,1); > > ub = ones(5,1); > > [m,n] =size(M); > > [x,resnorm,residual,exitflag,output,lambda] = lsqlin(M,r,-eye(n,n),zeros(n,1),[],[],lb,ub) > > > > however the solution (x) doesn't sum up to 1 : > > Yes, but that does not do what you want. > > What does it do? > > The first two args form the least squares problem > > min(norm(M*a - r)) > > This part is reasonable. > > Setting the lower bounds (lb) to be zeros(5,1) is also fine. > However, there is no reason to set an upper bound on > the parameters. If you know they are all positive, and the > sum is 1, then can any of them exceed 1? > > Next, what is the purpose of the 3rd and 4th arguments? > All they do are form a set of INEQUALITY constraints on > the parameters, forcing them to be positive numbers. > However, you already did that with the lower bounds! > So these arguments are redundant. > > Finally, where have you tried to put in a sum constraint? > What is the sum of the elements of a? Can you form the > sum using a dot product? Yes. > > ones(1,5)*a == 1 > > is an equality constraint that yields the sum of your elements. > So now, put it into a call to lsqlin. This is all you need. > > a = lsqlin(M,r,[],[],ones(1,5),1,lb); > > HTh, > John Thank you very much John, I've understood your explanation and now getting the right results . Thanks again, you've been very helpful. Merel.
|
Pages: 1 Prev: svmtrain problem Next: Locating indices of more than one of the maximum values of anarray |