Avoiding loops in bootstrap

11 次查看(过去 30 天)
Marco Lago
Marco Lago 2020-10-22
回答: Adam Danz 2020-10-22
I've nested loops to bootstrap a statistical test results. The code works but it's very slow. Is there a way to improve the below a structure and speed up the code:
for jj = 1:nreplications
Y_artificial %Simulate artificial data;
% Nested loop
for
%Perform test on recursive sub-samples of Y_artificial
end
end

回答(1 个)

Adam Danz
Adam Danz 2020-10-22
Bootstrapping is an iterative process. Even if you use a method that doesn't require you to write a loop, the functions you're using will very likely use loops.
Loops likely aren't the bottleneck in your code. Something else it. You could use Matlab's profiler to time your code and produce a summary of time consumption.
Also note Matlab's bootstrapping functions
but depending on what you're bootstrapping, it may be easier to built it yourself.

Community Treasure Hunt

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

Start Hunting!

Translated by