Speed up Block Stationary Bootstrap
2 ビュー (過去 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".
0 件のコメント
回答 (1 件)
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’.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!