Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fmincon + interior point algorithm + memory problems

Subject: fmincon + interior point algorithm + memory problems

From: Saad

Date: 4 Dec, 2012 13:35:08

Message: 1 of 10

Dear All,

I keep receiving this error message when implementing an optimization with fmincon (interior point algorithm). I seems that it is a memory problem, any clue of how to fix this one please?

??? Error using ==> ldl
Out of memory. Type HELP MEMORY for your options.

Here is my code:

beq = [ 1 const1 const2]' ;

months={'Jan', 'Feb', ...,'Dec'};

     for i=1997

        for j=1:length(months)
                    
                      
            w0=xlsread(P:\excelfile.xls ,'Begin','S5:S5000');
            a1=xlsread(['P:\excelfile.xls,'Begin','H5:H5000');
            a2=xlsread(['P:\excel file.xls'],'Begin','Z5:Z5000');
            
            
            a = [a1, a2];
            n = size(a,1) ;
         
            Aeq = vertcat(ones(1,n),a') ;
            lb = zeros(n,1) ;
            H = eye(n) ;
            [w,fval, exitflag] = fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options);
      
      
        end
        
     end

Any guidance or advice is much appreciated.
Regards

Saad

Subject: fmincon + interior point algorithm + memory problems

From: Alan_Weiss

Date: 4 Dec, 2012 13:49:15

Message: 2 of 10

On 12/4/2012 8:35 AM, Saad wrote:
> Dear All,
> I keep receiving this error message when implementing an optimization
> with fmincon (interior point algorithm). I seems that it is a memory
> problem, any clue of how to fix this one please?
>
> ??? Error using ==> ldl
> Out of memory. Type HELP MEMORY for your options.
>
> Here is my code:
>
> beq = [ 1 const1 const2]' ;
> months={'Jan', 'Feb', ...,'Dec'};
> for i=1997
>
> for j=1:length(months)
> w0=xlsread(P:\excelfile.xls ,'Begin','S5:S5000');
> a1=xlsread(['P:\excelfile.xls,'Begin','H5:H5000');
> a2=xlsread(['P:\excel file.xls'],'Begin','Z5:Z5000');
> a = [a1, a2];
> n = size(a,1) ; Aeq =
> vertcat(ones(1,n),a') ; lb = zeros(n,1) ; H =
> eye(n) ; [w,fval, exitflag] =
> fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options);
> end
> end
>
> Any guidance or advice is much appreciated. Regards
>
> Saad

It is possible that you need to use a memory-saving Hessian. Try setting
the option Hessian to 'lbfgs'. See
http://www.mathworks.com/help/optim/ug/fmincon.html#f186882

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: fmincon + interior point algorithm + memory problems

From: Matt J

Date: 4 Dec, 2012 14:33:07

Message: 3 of 10

"Saad" wrote in message <k9ku6c$l3j$1@newscl01ah.mathworks.com>...
>
> Aeq = vertcat(ones(1,n),a') ;
> lb = zeros(n,1) ;
> H = eye(n) ;
> [w,fval, exitflag] = fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options);
================

 You could use H=speye(n) instead of H=eye(n). Also, lsqnonneg or quadprog might be more efficient than fmincon.

Subject: fmincon + interior point algorithm + memory problems

From: Saad

Date: 4 Dec, 2012 18:28:08

Message: 4 of 10

"Matt J" wrote in message <k9l1j3$53o$1@newscl01ah.mathworks.com>...
> "Saad" wrote in message <k9ku6c$l3j$1@newscl01ah.mathworks.com>...
> >
> > Aeq = vertcat(ones(1,n),a') ;
> > lb = zeros(n,1) ;
> > H = eye(n) ;
> > [w,fval, exitflag] = fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options);
> ================
>
> You could use H=speye(n) instead of H=eye(n). Also, lsqnonneg or quadprog might be more efficient than fmincon.

Hi Matt

Thanks a lot for your reply. I did try speye(n) with fmincon but the problem still occurs. Unfortunately I cannot use lsqnonneg because I have constraints. I may be wrong but I don't think my problem can be written in a form of quadprog because I cannot modify "x" in the quadratic optimization function. I could potentially use lsqlin but here again it doesn't work I get a NaN value and it says "Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. "

Alan kindly suggested to use 'Hessian','lbfgs' with the fmincon and this time it works but when I check the optimized variables they all have the same value. Don't get me wrong I am not an expert in optimization, but it is weird to have the same value for the optimized variables? Shall I relax the tolerance? or do you think that it may be a problem inherent to my optimization function?

Thank you

With Regards

S

Subject: fmincon + interior point algorithm + memory problems

From: Saad

Date: 4 Dec, 2012 18:32:08

Message: 5 of 10

Alan_Weiss <aweiss@mathworks.com> wrote in message <k9kv0r$o2t$1@newscl01ah.mathworks.com>...
> On 12/4/2012 8:35 AM, Saad wrote:
> > Dear All,
> > I keep receiving this error message when implementing an optimization
> > with fmincon (interior point algorithm). I seems that it is a memory
> > problem, any clue of how to fix this one please?
> >
> > ??? Error using ==> ldl
> > Out of memory. Type HELP MEMORY for your options.
> >
> > Here is my code:
> >
> > beq = [ 1 const1 const2]' ;
> > months={'Jan', 'Feb', ...,'Dec'};
> > for i=1997
> >
> > for j=1:length(months)
> > w0=xlsread(P:\excelfile.xls ,'Begin','S5:S5000');
> > a1=xlsread(['P:\excelfile.xls,'Begin','H5:H5000');
> > a2=xlsread(['P:\excel file.xls'],'Begin','Z5:Z5000');
> > a = [a1, a2];
> > n = size(a,1) ; Aeq =
> > vertcat(ones(1,n),a') ; lb = zeros(n,1) ; H =
> > eye(n) ; [w,fval, exitflag] =
> > fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options);
> > end
> > end
> >
> > Any guidance or advice is much appreciated. Regards
> >
> > Saad
>
> It is possible that you need to use a memory-saving Hessian. Try setting
> the option Hessian to 'lbfgs'. See
> http://www.mathworks.com/help/optim/ug/fmincon.html#f186882
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Hi Alan

Thanks a lot for your reply. I did try what you suggested: 'Hessian','lbfgs' with the fmincon and this time it works but when I check the optimized variables they all have the same value. Don't get me wrong I am not an expert in optimization, but it is weird to have the same value for the optimized variables? Shall I relax the tolerance? or do you think that it may be a problem inherent to my optimization function?

Thank you

With Regards

S

Subject: fmincon + interior point algorithm + memory problems

From: Alan_Weiss

Date: 4 Dec, 2012 19:14:26

Message: 6 of 10

On 12/4/2012 1:32 PM, Saad wrote:
> Alan_Weiss <aweiss@mathworks.com> wrote in message
> <k9kv0r$o2t$1@newscl01ah.mathworks.com>...
>> On 12/4/2012 8:35 AM, Saad wrote:
>> > Dear All,
>> > I keep receiving this error message when implementing an
>> optimization > with fmincon (interior point algorithm). I seems that
>> it is a memory > problem, any clue of how to fix this one please?
>> >
>> > ??? Error using ==> ldl
>> > Out of memory. Type HELP MEMORY for your options.
>> >
>> > Here is my code:
>> >
>> > beq = [ 1 const1 const2]' ;
>> > months={'Jan', 'Feb', ...,'Dec'};
>> > for i=1997
>> >
>> > for j=1:length(months)
>> > w0=xlsread(P:\excelfile.xls ,'Begin','S5:S5000');
>> > a1=xlsread(['P:\excelfile.xls,'Begin','H5:H5000');
>> > a2=xlsread(['P:\excel file.xls'],'Begin','Z5:Z5000');
>> > a = [a1, a2];
>> > n = size(a,1) ; Aeq = >
>> vertcat(ones(1,n),a') ; lb = zeros(n,1) ; H = > eye(n)
>> ; [w,fval, exitflag] = >
>> fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options);
>> > end
>> > end
>> >
>> > Any guidance or advice is much appreciated. Regards
>> >
>> > Saad
>>
>> It is possible that you need to use a memory-saving Hessian. Try
>> setting the option Hessian to 'lbfgs'. See
>> http://www.mathworks.com/help/optim/ug/fmincon.html#f186882
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation
>
> Hi Alan
>
> Thanks a lot for your reply. I did try what you suggested:
> 'Hessian','lbfgs' with the fmincon and this time it works but when I
> check the optimized variables they all have the same value. Don't get
> me wrong I am not an expert in optimization, but it is weird to have
> the same value for the optimized variables? Shall I relax the
> tolerance? or do you think that it may be a problem inherent to my
> optimization function?
>
> Thank you
>
> With Regards
>
> S

I don't know what your data files contain, and I don't understand how
your loops change the optimization results, but I bet you can figure it
out yourself. Try some of the suggestions in
http://www.mathworks.com/help/optim/ug/when-the-solver-might-have-succeeded.html

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: fmincon + interior point algorithm + memory problems

From: Matt J

Date: 4 Dec, 2012 21:19:10

Message: 7 of 10



 I may be wrong but I don't think my problem can be written in a form of quadprog because I cannot modify "x" in the quadratic optimization function.
================

It can be written in the form required by quadprog, but you're right that lsqlin looks more directly applicable.


  I could potentially use lsqlin but here again it doesn't work I get a NaN value and it says "Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. "
>
> Alan kindly suggested to use 'Hessian','lbfgs' with the fmincon and this time it works but when I check the optimized variables they all have the same value. Don't get me wrong I am not an expert in optimization, but it is weird to have the same value for the optimized variables? Shall I relax the tolerance? or do you think that it may be a problem inherent to my optimization function?
===============

From the output of LSQLIN, it sounds like you have bad data. As for all the variables having the same value, that depends on w0 and other problem data. It should be easy enough to check whether optimality conditions are satisfied at the solution given.

Subject: fmincon + interior point algorithm + memory problems

From: Saad

Date: 5 Dec, 2012 10:02:07

Message: 8 of 10

Alan_Weiss <aweiss@mathworks.com> wrote in message <k9li2i$bjj$1@newscl01ah.mathworks.com>...
> On 12/4/2012 1:32 PM, Saad wrote:
> > Alan_Weiss <aweiss@mathworks.com> wrote in message
> > <k9kv0r$o2t$1@newscl01ah.mathworks.com>...
> >> On 12/4/2012 8:35 AM, Saad wrote:
> >> > Dear All,
> >> > I keep receiving this error message when implementing an
> >> optimization > with fmincon (interior point algorithm). I seems that
> >> it is a memory > problem, any clue of how to fix this one please?
> >> >
> >> > ??? Error using ==> ldl
> >> > Out of memory. Type HELP MEMORY for your options.
> >> >
> >> > Here is my code:
> >> >
> >> > beq = [ 1 const1 const2]' ;
> >> > months={'Jan', 'Feb', ...,'Dec'};
> >> > for i=1997
> >> >
> >> > for j=1:length(months)
> >> > w0=xlsread(P:\excelfile.xls ,'Begin','S5:S5000');
> >> > a1=xlsread(['P:\excelfile.xls,'Begin','H5:H5000');
> >> > a2=xlsread(['P:\excel file.xls'],'Begin','Z5:Z5000');
> >> > a = [a1, a2];
> >> > n = size(a,1) ; Aeq = >
> >> vertcat(ones(1,n),a') ; lb = zeros(n,1) ; H = > eye(n)
> >> ; [w,fval, exitflag] = >
> >> fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options);
> >> > end
> >> > end
> >> >
> >> > Any guidance or advice is much appreciated. Regards
> >> >
> >> > Saad
> >>
> >> It is possible that you need to use a memory-saving Hessian. Try
> >> setting the option Hessian to 'lbfgs'. See
> >> http://www.mathworks.com/help/optim/ug/fmincon.html#f186882
> >>
> >> Alan Weiss
> >> MATLAB mathematical toolbox documentation
> >
> > Hi Alan
> >
> > Thanks a lot for your reply. I did try what you suggested:
> > 'Hessian','lbfgs' with the fmincon and this time it works but when I
> > check the optimized variables they all have the same value. Don't get
> > me wrong I am not an expert in optimization, but it is weird to have
> > the same value for the optimized variables? Shall I relax the
> > tolerance? or do you think that it may be a problem inherent to my
> > optimization function?
> >
> > Thank you
> >
> > With Regards
> >
> > S
>
> I don't know what your data files contain, and I don't understand how
> your loops change the optimization results, but I bet you can figure it
> out yourself. Try some of the suggestions in
> http://www.mathworks.com/help/optim/ug/when-the-solver-might-have-succeeded.html
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Thank you Alan. I will investigate the issue a bit more. Thanks again!

Regards

S

Subject: fmincon + interior point algorithm + memory problems

From: Saad

Date: 5 Dec, 2012 10:15:08

Message: 9 of 10

"Matt J" wrote in message <k9lpce$aio$1@newscl01ah.mathworks.com>...
>
>
> I may be wrong but I don't think my problem can be written in a form of quadprog because I cannot modify "x" in the quadratic optimization function.
> ================
>
> It can be written in the form required by quadprog, but you're right that lsqlin looks more directly applicable.
>
>
> I could potentially use lsqlin but here again it doesn't work I get a NaN value and it says "Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. "
> >
> > Alan kindly suggested to use 'Hessian','lbfgs' with the fmincon and this time it works but when I check the optimized variables they all have the same value. Don't get me wrong I am not an expert in optimization, but it is weird to have the same value for the optimized variables? Shall I relax the tolerance? or do you think that it may be a problem inherent to my optimization function?
> ===============
>
> From the output of LSQLIN, it sounds like you have bad data. As for all the variables having the same value, that depends on w0 and other problem data. It should be easy enough to check whether optimality conditions are satisfied at the solution given.

Hi Matt,

You mentioned that the problem could be written in quadprog. In the optimization, fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options) w0 is a constant. If possible could you please show me how I can rewrite the problem so that it could fit the quadprog function? Thanks so much

Regards

S

Subject: fmincon + interior point algorithm + memory problems

From: Matt J

Date: 5 Dec, 2012 18:00:09

Message: 10 of 10

"Saad" wrote in message <k9n6rc$9q1$1@newscl01ah.mathworks.com>...
>
> You mentioned that the problem could be written in quadprog. In the optimization, fmincon(@(x)norm(H*x-w0)^2,w0,[],[],Aeq,beq,lb,[],[],options) w0 is a constant. If possible could you please show me how I can rewrite the problem so that it could fit the quadprog function? Thanks so much
============

x.'*(H.'*H)*x/2 - dot(H*w0, x)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us