Speed up Block Stationary Bootstrap

2 views (last 30 days)
Ricardo Henriquez
Ricardo Henriquez on 18 Jul 2023
Answered: Keshav on 26 Jul 2023
Hello,
I am currently working with Kevin Sheppard's block bootstrap code for my project, but I've noticed that it becomes slow for bootstraps exceeding 10^6. I'm looking for suggestions on how to optimize and speed up the code, possibly through parallelization or other techniques. Your expertise and insights are highly appreciated. Thank you!
Slide 34.
n = 300; y = randn(n,1);
T=size(y,1);
% Average block size
m = 10;
%Nbootstraps
B = 10^6;
% Loop over B bootstraps
yRepl = [y;y];
u = zeros(T,1);
tic
for b=1:B
u(1) = ceil(T*rand);
for t=2:T
if rand<1/m
u(t) = ceil(T*rand);
else
u(t) = u(t-1) + 1;
end
end
% y-star sample simulation
yStar = yRepl(u);
% Mean of y-star
muStar(b) = mean(yStar);
end
toc
I've tried a parfor-loop but I am getting the following error on u.
Unable to classify the variable 'u' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in parfor-Loops".

Answers (1)

Keshav
Keshav on 26 Jul 2023
Hi,
You can look at the below MathWorks documentation to resolve the error you are getting while using the ‘parfor-loop’.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!