为什么matlab bootstrap程序评估N + 1次?

时间:2016-03-09 14:22:56

标签: matlab bootstrapping

我想使用内置命令" bootstrp"来使用matlab进行引导。我注意到的是,当我只要求N次迭代时,该过程进行N + 1次迭代。这是为什么?当我构建一个手动循环来进行引导时,它实际上只运行N次,然后它更快。以下是问题的最小示例:

mysql>

使用函数

clear all

global iterationcounter

tic

iterationcounter=0;
data=unifrnd(0,1,1,1000); %draw vector of 1000 random numbers

bootstat = bootstrp(100,@testmean,data); %evaluate function for 100 bootstrap samples
toc

该函数应该评估100个样本,但是当我运行脚本时,它将评估该函数101次:

  

...

     

iterationcounter =

     

101

     

经过的时间是0.102291秒。

那么为什么要使用这种内置的Matlab函数来浪费时间呢?

1 个答案:

答案 0 :(得分:1)

bootstrp调用bootfun(函数参数)进行健全性检查(来自源代码,MATLAB 2015b,bootstrp.m,l.167 ff):

% Sanity check bootfun call and determine dimension and type of result
try
    % Get result of bootfun on actual data, force to a row.
    bootstat = feval(bootfun,bootargs{:});
    bootstat = bootstat(:)';
catch ME
    m = message('stats:bootstrp:BadBootFun');
    MEboot =  MException(m.Identifier,'%s',getString(m));
    ME = addCause(ME,MEboot);
    rethrow(ME);
end

我认为在实际应用中N>>100,所以额外的开销(很多)小于其总运行时间的百分比(不考虑可能并行化的速度增益),所以不应该那么重要吗?