Is there a way to retrieve the computed PCE from UQlab even after Matlab gives the error due to full memory?
I am running a PCE for a large problem and testing various PCE degree truncations. For some degree, however, Matlab produces an error due to its limited memory. Is there a possibility to retrieve the last successful PCE that did not fill the memory?
I can think of many ways to do this. Two very easy ones are:
Dump every successfully create PCE model to a file and after the memory error occurred load the one you need
Wrap everything into a try-catch block like so:
for i = 1:100
try
a = zeros(10^i);
catch ME
% Check the exact error you got
if strcmp(ME.identifier, 'MATLAB:array:SizeLimitExceeded')
break % or continue (depends on what you want)
else
rethrow(ME);
end
end
end
% This is the last sucessfully allocated matrix
disp(size(a))
i checked it out and I added a little modification to collect another kind of error.
for i = 1:100
try
a = zeros(10^i);
catch ME
% Check the exact error you got
if strcmp(ME.identifier, 'MATLAB:array:SizeLimitExceeded') | strcmp(ME.identifier, 'MATLAB:nomem')
break % or continue
else
rethrow(ME);
end
end
end
% This is the last sucessfully allocated matrix
disp(size(a))