Fast Sampling From A Discrete Distribution

バージョン 1.0.0.0 (3.58 KB) 作成者: Peng Liu
This function generates independent random samples according to a prescribed discrete distribution.
ダウンロード: 242
更新 2016/10/14

ライセンスの表示

This function generates independent random samples according to a prescribed discrete distribution. It accepts as inputs the discrete probability mass function, the size of the random matrix to be generated, and an optional input parameter which specifies the data type of the output (default to double). The output is a random matrix.

>> x = randsmpl(p, m, n)
returns an m-by-n matrix x of random samples drawn independently from the input (discrete) distribution specified with pmf p. Suppose that the sample space comprises K samples, then p must be a (row- or column-) vector containing K probability masses summing to 1. The output, x(i,j) = k, k = 1, ..., K, describes that the k-th sample is drawn in the (i,j)-th trial, for i = 1, ..., m and j = 1,...,n. The default output data type of x is 'double'.

>> x = randsmpl(p, m, n, classname)
returns an m-by-n matrix x whose data type is specified by classname. The classname input must be a valid numeric class name which includes the following
'double' (default) | 'single' | 'int64' | 'int32' | 'int16' | 'int8' | 'uint64' | 'uint32' | 'uint16' | 'uint8' |
If classname is not provided, it is default to 'double'.

The implementation of randsmpl is based on the discretize function, which was introduced in R2015a. For backward compatibility, we also provided an interp1 alternative. randsmpl is smart enough that it will automatically determine whether to use discretize or interp1 according to users' MATLAB version.

This function is extremely useful for fast sampling for Monte Carlo simulations. The performance and robustness of the function are highly optimized. Comments and suggestions will be appreciated.

引用

Peng Liu (2024). Fast Sampling From A Discrete Distribution (https://www.mathworks.com/matlabcentral/fileexchange/59724-fast-sampling-from-a-discrete-distribution), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2015a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersRandom Number Generation についてさらに検索
謝辞

ヒントを得たファイル: Sampling from a discrete distribution

Community Treasure Hunt

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

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

more accurate title
Improved documentation
N/A

Better description
N/A