Commit 89326090 authored by Johannes Pfeifer 's avatar Johannes Pfeifer

simpsa: Only store output strcuture if requested

Otherwise a huge three-dimensional array is created by default that is not used, but can run computer out of memory
parent 54d28d65
...@@ -142,8 +142,9 @@ DEFAULT_OPTIONS = simpsaset('TEMP_START',[],... % starting temperature (if none ...@@ -142,8 +142,9 @@ DEFAULT_OPTIONS = simpsaset('TEMP_START',[],... % starting temperature (if none
OPTIONS = simpsaset(DEFAULT_OPTIONS,OPTIONS); OPTIONS = simpsaset(DEFAULT_OPTIONS,OPTIONS);
% store options in OUTPUT % store options in OUTPUT
if nargout>3
OUTPUT.OPTIONS = OPTIONS; OUTPUT.OPTIONS = OPTIONS;
end
% initialize simplex % initialize simplex
% ------------------ % ------------------
...@@ -175,13 +176,13 @@ end ...@@ -175,13 +176,13 @@ end
% initialize OUTPUT structure % initialize OUTPUT structure
% --------------------------- % ---------------------------
if nargout>3
OUTPUT.TEMPERATURE = zeros(OPTIONS.MAX_ITER_TOTAL,1); OUTPUT.TEMPERATURE = zeros(OPTIONS.MAX_ITER_TOTAL,1);
OUTPUT.SIMPLEX = zeros(NDIM+1,NDIM,OPTIONS.MAX_ITER_TOTAL); OUTPUT.SIMPLEX = zeros(NDIM+1,NDIM,OPTIONS.MAX_ITER_TOTAL);
OUTPUT.SIMPLEX_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM); OUTPUT.SIMPLEX_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM);
OUTPUT.COSTS = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM+1); OUTPUT.COSTS = zeros(OPTIONS.MAX_ITER_TOTAL,NDIM+1);
OUTPUT.COST_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,1); OUTPUT.COST_BEST = zeros(OPTIONS.MAX_ITER_TOTAL,1);
end
% initialize iteration data % initialize iteration data
% ------------------------- % -------------------------
...@@ -304,17 +305,19 @@ while 1 ...@@ -304,17 +305,19 @@ while 1
Y = help(:,2); Y = help(:,2);
P = help(:,3:end); P = help(:,3:end);
% store temperature at current iteration if nargout>3
OUTPUT.TEMPERATURE(nITERATIONS) = TEMP; % store temperature at current iteration
OUTPUT.TEMPERATURE(nITERATIONS) = TEMP;
% store information about simplex at the current iteration
OUTPUT.SIMPLEX(:,:,nITERATIONS) = P;
OUTPUT.SIMPLEX_BEST(nITERATIONS,:) = PBEST;
% store cost function value of best vertex in current iteration % store information about simplex at the current iteration
OUTPUT.COSTS(nITERATIONS,:) = Y; OUTPUT.SIMPLEX(:,:,nITERATIONS) = P;
OUTPUT.COST_BEST(nITERATIONS) = YBEST; OUTPUT.SIMPLEX_BEST(nITERATIONS,:) = PBEST;
% store cost function value of best vertex in current iteration
OUTPUT.COSTS(nITERATIONS,:) = Y;
OUTPUT.COST_BEST(nITERATIONS) = YBEST;
end
if strcmp(OPTIONS.DISPLAY,'iter') if strcmp(OPTIONS.DISPLAY,'iter')
disp(sprintf('%5.0f %5.0f %12.6g %15.6g %12.6g %s',nITERATIONS,nFUN_EVALS,Y(1),YBEST,TEMP,ALGOSTEP)); disp(sprintf('%5.0f %5.0f %12.6g %15.6g %12.6g %s',nITERATIONS,nFUN_EVALS,Y(1),YBEST,TEMP,ALGOSTEP));
end end
...@@ -452,21 +455,23 @@ end ...@@ -452,21 +455,23 @@ end
X = transpose(PBEST); X = transpose(PBEST);
FVAL = YBEST; FVAL = YBEST;
% store number of function evaluations if nargout>3
OUTPUT.nFUN_EVALS = nFUN_EVALS; % store number of function evaluations
OUTPUT.nFUN_EVALS = nFUN_EVALS;
% store number of iterations
OUTPUT.nITERATIONS = nITERATIONS; % store number of iterations
OUTPUT.nITERATIONS = nITERATIONS;
% trim OUTPUT data structure
OUTPUT.TEMPERATURE(nITERATIONS+1:end) = []; % trim OUTPUT data structure
OUTPUT.SIMPLEX(:,:,nITERATIONS+1:end) = []; OUTPUT.TEMPERATURE(nITERATIONS+1:end) = [];
OUTPUT.SIMPLEX_BEST(nITERATIONS+1:end,:) = []; OUTPUT.SIMPLEX(:,:,nITERATIONS+1:end) = [];
OUTPUT.COSTS(nITERATIONS+1:end,:) = []; OUTPUT.SIMPLEX_BEST(nITERATIONS+1:end,:) = [];
OUTPUT.COST_BEST(nITERATIONS+1:end) = []; OUTPUT.COSTS(nITERATIONS+1:end,:) = [];
OUTPUT.COST_BEST(nITERATIONS+1:end) = [];
% store the amount of time needed in OUTPUT data structure
OUTPUT.TIME = toc; % store the amount of time needed in OUTPUT data structure
OUTPUT.TIME = toc;
end
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment