Sampling from a discrete distribution

バージョン 1.1.0.0 (2.25 KB) 作成者: Dahua Lin
The function is to draw samples from an arbitrary discrete distribution.
ダウンロード: 7K
更新 2008/10/28

ライセンスの表示

There are a lot of cases that you might need to sample from a discrete distribution in Monte Carlo simulations. Here are some typical examples that this function may help

(1) you want to sample from a discrete distribution over finitely many categories(labels). However, the pmf is not easy to directly sample from. Then you can just compute p(k) for each category, and then use this function to do the sampling.

(2) For a general (possibly non-parametric) continuous distribution defined in a 1D/2D space, you may discretized the sample space into small regions, and compute the probability mass for these regions, and then use this function to do the sampling.

(3) In many models, the probability distribution is expressed as a weighted sum of several "modes". To sample from this kind of distributions, you may need to first choose which mode to generate the sample according to their weights, then this function may fit in.

In sum, this function can be used directly in simple sampling, and may also be used as a building block of complicated simulation procedure.

The use of this function is easy:

x = discretesample(p, n).

You just input the probability mass, and tell the function how many sample you want to sample, then it returns the samples in form of a 1 x n vector.

引用

Dahua Lin (2024). Sampling from a discrete distribution (https://www.mathworks.com/matlabcentral/fileexchange/21912-sampling-from-a-discrete-distribution), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2008a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
謝辞

ヒントを与えたファイル: Fast Sampling From A Discrete Distribution, Lynx MATLAB Toolbox

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.1.0.0

Fixing a bug that may lead to incorrect sampling.

1.0.0.0