implement jackknife using parallel computing -凯发k8网页登录

main content

implement jackknife using parallel computing

this example is from the 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);

run 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.

网站地图