This example is from the
jackknife function 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);
jackknife in parallel to estimate the variance. To do this, use
statset to create the options structure and set the
UseParallel field 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 formula jbias = (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.
jackknife does not use random numbers, so gives the same results
every time, whether run in parallel or serial.