Main Content

Implement Jackknife Using Parallel Computing

This example is from thejackknifefunction reference page, but runs in parallel.

Generate a sample data of size 10000 from a normal distribution with mean 0 and standard deviation 5.

sigma = 5; rng('default') y = normrnd(0,sigma,10000,1);

Runjackknifein parallel to estimate the variance. To do this, usestatsetto create the options structure and set theUseParallelfield to true.

opts = statset('UseParallel',true); m = jackknife(@var,y,1,'Options',opts);

Compare the known bias formula with the jackknife bias estimate.

n = length(y); bias = -sigma^2/n% Known bias formulajbias = (n-1)*(mean(m)-var(y,1))% jackknife bias estimate
Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 6). bias = -0.0025 jbias = -0.0025

Compare how long it takes to compute in serial and in parallel.

tic;m = jackknife(@var,y,1);toc% Serial computation
Elapsed time is 1.638026 seconds.
tic;m = jackknife(@var,y,1,'Options',opts);toc% Parallel computation
Elapsed time is 0.507961 seconds.

jackknifedoes not use random numbers, so gives the same results every time, whether run in parallel or serial.