fminsearch and out of memory
2 views (last 30 days)
Show older comments
i have some problem with function fminsearch in matlab 7. I have variable r which sets dimensions of matrix. For my problems its looks like this:
for i=1:10
for j=1:3
......
r(1)=i-1;
r(2)=j-1;
r(3)=q-1;
....
Each iteration of dimensions looks like:
fwrap = @(ab) wrap_linear_dynamic(r,ab);
[ab] = fminsearch(fwrap,zeros(1,columns(ab)),optimset('MaxIter',2000,'Display','off'));
function [result] = wrap_linear_dynamic(r,ab)
global ayw shifty;
b = ab(1, columns(ab)-r(columns(r)):columns(ab));
a = ab(1, 1: columns(ayw)- columns(b));
result=criterion_linear_dynamic(a,b);
end
function [result]=criterion_linear_dynamic(a,b,Dy,Dx)
....
global ayw shifty;
.....
u = uf(a,b);
...
w = wf(a,b,Dx,Dy);
result = u*(w^-1);
clear w u Dx Dy;
end
function [resultw]=wf(a,b,Dx,Dy)
d = 1:columns(a);
if max(Dx) > 0
Do = (Dx.^2)/(Dy.^2);
else
Do = Dx;
end
resultw = Dy*(1+dot(b',b)+sum(Do(:,d)*dot(a(:,d)',a(:,d))));
end
function [resultu]=uf(a,b)
global ayw shifty;
ab = vertcat(a',b');
resultu = sum((shifty-ayw*(ab)).^2);
end
Question: Dimensions of matrix ayw [130,10] and shifty[130,1]. if Dimension of matrix ayw becomes more 130:x. i get the error: out of memory on fminsearch.
??? Error using ==> max
Out of memory. Type HELP MEMORY for your options.
Error in ==> criterion_linear_dynamic>wf at 68
if max(Dx) > 0
Error in ==> criterion_linear_dynamic at 35
w = wf(a,b,Dx,Dy);
Error in ==> wrap_linear_dynamic at 8
result=criterion_linear_dynamic(a,b);
Error in ==>
optim_linear_dynamic>@(ab)wrap_linear_dynamic(r,ab) at 28
fwrap = @(ab) wrap_linear_dynamic(r,ab);
Error in ==> fminsearch at 191
fv(:,1) = funfcn(x,varargin{:});
Error in ==> optim_linear_dynamic at 29
[ab] = fminsearch(fwrap,zeros(1,columns(ab)),optimset('MaxIter',2000,'Display','off'));%,'PlotFcns',@optimplotfval));
Error in ==> optim_values_test7d at 21
[curcrit,a,b,curcrit_test_data,std_error]
= optim_linear_dynamic(x,y,rz);
I used the profiler, the memory begins to increase nonlinear rapidly in fminsearch. Apparently this is somehow directly connected with the algorithm for minimization. Are there ways to reduce memory usage fminsearch?
0 Comments
Answers (1)
Walter Roberson
on 5 Aug 2011
Is there a reason that you call criterion_linear_dynamic with only two arguments even though it is defined with four arguments?
What kind of size is Dx ? And is it possibly an array instead of a vector?
2 Comments
Walter Roberson
on 6 Aug 2011
If Dx is small, you could try instead
if any(Dx(:) > 0)
or write the equivalent in to a loop.
I don't promise it will solve the problem; indeed, if it does, then the implication would be that Dx somehow become an array.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!