【问题标题】:How to show that randperm() in matlab is fair如何在 matlab 中证明 randperm() 是公平的
【发布时间】:2018-11-23 09:24:05
【问题描述】:

假设,我想(凭经验)证明 matlab 中的 randperm(n,k) 确实从 n 个元素的集合 N 中产生大小为 k 的均匀分布的随机样本。重复绘制后,如何绘制出现次数除以从 N 绘制的 k 子集的总数?

【问题讨论】:

    标签: matlab probability combinatorics


    【解决方案1】:

    您可以简单地使用从randperm 提取的索引来增加计数器向量。

    n=1e5;
    k=1e4;
    maxiter = 1e5;
    
    % This array will be used to count the number of times each integer has been drawn
    count=zeros(n,1);
    
    for ii=1:maxiter
        p=randperm(n,k);
        % p is a vector of k distinct integers in the 1:n range
        % the array count will be incremented at indices given by p
        count(p)=count(p)+1;
    end
    
    % A total of k*maxiter integers has been drawn and they should be evenly
    % distributed over n values
    % The following vector should have values close to 1 for large values of maxiter
    prob = count*n/(k*maxiter);
    

    【讨论】:

      猜你喜欢
      • 2022-08-08
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 2014-08-03
      • 2014-03-27
      相关资源
      最近更新 更多