Speed up Block Stationary Bootstrap

3 次查看(过去 30 天)
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".

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by