Speed up Block Stationary Bootstrap
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Keshav
le 26 Juil 2023
Hi,
You can look at the below MathWorks documentation to resolve the error you are getting while using the ‘parfor-loop’.
0 commentaires
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!