Skip to content

Commit

Permalink
cleaning up test benchmark as discussed with Linus
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Tamellini committed Dec 11, 2023
1 parent 2e7da23 commit 4b58a66
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions benchmarks/cookies-problem/run_forward_benchmark_in_matlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
% addpath(genpath('~/GIT_projects/Github/umbridge/matlab/'))


% 3) to regenerate the files with the results (sparse grids in .txt and .mat, results in .txt and .mat), set the flag below to true
% 3) to save results on file (sparse grids in .txt / .mat, results in .txt / .mat), set the flag below to true
saving_stuff = true;


% 4) to plot results, set the flag below to true
plotting = true;


%% setup model

% specify model port
Expand All @@ -39,7 +43,8 @@

%% create sparse grid

% setup sparse grid ingredients. We will build increasingly large grids using a for loop
% setup sparse grid ingredients. Instead of building the final grid in one go, we build it gradaully using a for
% loop that creates a sequence of nested grids

N = 8;
knots = @(n) knots_CC(n,-0.99,-0.2);
Expand All @@ -48,8 +53,7 @@
idxset_level_max = 1; % <--- controls max size of sparse grid


% With the choice above, the sparse grids will be nested. To recycle evaluations from one grid
% to the next, we need some containers
% To recycle evaluations from one grid to the next, we need some containers

S_old = []; % the previous sparse grid in extended format
Sr_old = []; % the previous sparse grid in reduced format
Expand Down Expand Up @@ -84,8 +88,6 @@
grid_filename_mat = grid_filename(1:end-4); % i.e., remove .txt
save(grid_filename_mat,'S','Sr','Psi_evals')
end



% compute expected value and append the new value to previous container. Same for nb_pts
Psi_EV(end+1) = quadrature_on_sparse_grid(Psi_evals,Sr); %#ok<SAGROW>
Expand All @@ -106,3 +108,16 @@
% save also on .mat
save('cookies-benchmark-output','nb_pts','Psi_EV')
end


if plotting
% in principle, only nb-pts and Psi_EV are needed, so if you have them on file already you can just load results
% load('cookies-benchmark-output')
figure
semilogx(nb_pts,Psi_EV,'-ok','LineWidth',2,'MarkerFaceColor','k','DisplayName','sparse grid approx. of $\mathbf{E}[\Psi]$')
grid on
xlabel('sparse grids points')
ylabel('$\mathbf{E}[\Psi]$','interpreter','latex','rotation',0)
legend show
set(legend,'interpreter','latex','location','northwest','fontsize',14)
end

0 comments on commit 4b58a66

Please sign in to comment.