Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

Implement Jackknife Using Parallel Computing

This example is from the jackknife function reference page, but runs in parallel.

mypool=parpool()
Starting parpool using the 'local' profile ... connected to 2 workers.

mypool = 

  Pool with properties:

    AttachedFiles: {0x1 cell}
       NumWorkers: 2
      IdleTimeout: 30
          Cluster: [1x1 parallel.cluster.Local]
     RequestQueue: [1x1 parallel.RequestQueue]
      SpmdEnabled: 1
opts = statset('UseParallel',true);
sigma = 5;
rng('default')
y = normrnd(0,sigma,100,1);
m = jackknife(@var, y,1,'Options',opts);
n = length(y);
bias = -sigma^2 / n % known bias formula
jbias = (n - 1)*(mean(m)-var(y,1)) % jackknife bias estimate

bias =

   -0.2500


jbias =

   -0.3378

This simple example is not a good candidate for parallel computation:

% How long to compute in serial?
tic;m = jackknife(@var,y,1);toc
Elapsed time is 0.022771 seconds.

% How long to compute in parallel?
tic;m = jackknife(@var,y,1,'Options',opts);toc
Elapsed time is 0.299066 seconds.

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