【问题标题】:How to simulate the Hypergeometric distribution in Matlab如何在 Matlab 中模拟超几何分布
【发布时间】:2017-08-15 23:39:10
【问题描述】:

我想在 Matlab 程序中模拟具有概率质量函数和参数的超几何分布,如下所述:https://en.wikipedia.org/wiki/Hypergeometric_distribution 如何在从均匀分布中生成随机数的同时对其进行编码。

【问题讨论】:

  • Matlab provides a generator时为什么要编码?
  • @pjs 嘿,好球!
  • @pjs 我必须使用分发功能,而不是使用生成器,抱歉没有提及!

标签: matlab simulation probability distribution distributed-computing


【解决方案1】:

这很容易通过randperm 函数完成,它会生成一个无需替换的样本

让分布参数定义如下:

N = 10; % population size
K = 3;  % number of success states in the population
n = 5;  % number of draws

那么得到的变量k

k = sum(randperm(N,n)<=K);

具有参数N,K,n的超几何分布。


如果你真的需要使用统一随机数生成器(rand函数):

[~, x] = sort(rand(1,N));
x = x(1:n); % this gives the same result as randperm(N,n)
k = sum(x<=K);

【讨论】:

    【解决方案2】:

    最明智的做法是使用builtin hypergeometric generator

    如果您出于赋值或其他任意原因必须这样做,则存在逆 CDF 时的通用解决方案是进行反转 - 使用统一生成器创建 p 值(介于 0 和 1 之间的值),并将其插入逆 CDF。由于Matlab provides an inverse CDF function,这应该很简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 2019-10-14
      • 2020-12-21
      • 1970-01-01
      • 2016-10-11
      • 2011-08-12
      相关资源
      最近更新 更多